How are SQLServer Timestamp/RowVersion Values Created? I am relatively fresh to SQLServer's use of ROWVERSION/TIMESTAMP data, and normally just query for required rows based on modified dates.

How is the ROWVERSION assigned to a new row in a database? Does every new row start with the same rowversion, or is it a unique value? In other words, will a new row in the database have its rowversion set to currentMaxRowVersion+1?

The use case for this is to query for all rows whose data has changed since the last time the database was queried, EG:

SELECT * FROM MyTable WHERE RowVersion &gt; previousHighestRowVersion
Referencing the documentation for rowversion (Transact-SQL) - (highlighting mine)


  Each database has a counter that is incremented for each insert or
  update operation that is performed on a table that contains a
  rowversion column within the database. This counter is the database
  rowversion. This tracks a relative time within a database, not an
  actual time that can be associated with a clock. A table can have only
  one rowversion column. Every time that a row with a rowversion column
  is modified or inserted, the incremented database rowversion value is
  inserted in the rowversion column.





  You can use the rowversion column of a row to easily determine whether
  the row has had an update statement ran against it since the last time
  it was read. If an update statement is ran against the row, the
  rowversion value is updated. If no update statements are ran against
  the row, the rowversion value is the same as when it was previously
  read.




As far as being unique - it 'should' be unique across all tables in a database.  Here is the 'should' part - there is a caveat in the documentation:


  Duplicate rowversion values can be generated by using the SELECT INTO
  statement in which a rowversion column is in the SELECT list. We do
  not recommend using rowversion in this manner.




You can check the current database rowversion by using @@DBTS.  This example shows rowversion in action.

set nocount on
drop table if exists mytest
go
CREATE TABLE MyTest (myKey int PRIMARY KEY  
    ,myValue int, RV rowversion);  
GO   
INSERT INTO MyTest (myKey, myValue) VALUES (1, 0);  
GO   
select @@DBTS
go
INSERT INTO MyTest (myKey, myValue) VALUES (2, 0);  
GO  
select @@DBTS
go
update MyTest set myValue = myValue
go
select @@DBTS
go




------------------
0x0000000000009481

------------------
0x0000000000009482

------------------
0x0000000000009484