SQL Server Interview Question #243

What is the rowversion data type?

Advanced Transactions & Concurrency Senior Advanced

Detailed Explanation

rowversion is an automatically generated binary value that changes when a row containing a rowversion column is inserted or updated. It is unique within the database at the time it is generated.

Despite its historical synonym timestamp, rowversion does not store a date or time. It is commonly used for optimistic concurrency detection.

Applications should treat it as an opaque concurrency token rather than deriving business meaning from its numeric value.

Code Example

CREATE TABLE dbo.Products
(
    Id INT PRIMARY KEY,
    Name NVARCHAR(200) NOT NULL,
    Price DECIMAL(18,2) NOT NULL,
    RowVersion ROWVERSION
);