SQL ROWVERSION Data Type

The ROWVERSION data type automatically generates unique binary numbers.

ROWVERSION is used to 'stamp' table rows with a unique version number.

These numbers do not carry any meaning, unlike TIMESTAMP.

A table can only have one ROWVERSION column.

Example

#

A table with a ROWVERSION column.

CREATE TABLE DemoTable  
( 
  Id INT IDENTITY, 
  FullName VARCHAR(100),
  Address VARCHAR(250),
  Version ROWVERSION
);
GO  

INSERT INTO DemoTable VALUES ('Harold Smith', '3526 Sherman Street, Lawrence, Kansas');  
INSERT INTO DemoTable VALUES ('Robert Johnson', '1673 Sampson Street, Denver, Colorado');  
INSERT INTO DemoTable VALUES ('Janice Lopez', '70 Clearview Drive, Pheba, Mississippi');
INSERT INTO DemoTable VALUES ('Kelly Wilson', '3393 Rockford Road, Charlestown, Massachusetts'); 
INSERT INTO DemoTable VALUES ('Grace Taylor', '4057 Berkley Street, Philadelphia, Pennsylvania'); 
GO  

SELECT * FROM DemoTable;
GO

DROP TABLE DemoTable;
GO
Result:  5 records
Id FullName Address Version
1 Harold Smith 3526 Sherman Street, Lawrence, Kansas 0x00000000000036D9
2 Robert Johnson 1673 Sampson Street, Denver, Colorado 0x00000000000036DA
3 Janice Lopez 70 Clearview Drive, Pheba, Mississippi 0x00000000000036DB
4 Kelly Wilson 3393 Rockford Road, Charlestown, Massachusetts 0x00000000000036DC
5 Grace Taylor 4057 Berkley Street, Philadelphia, Pennsylvania 0x00000000000036DD

You may also like



Guides


vsn 3.1