Fer
Fer

Reputation: 1992

Timestamp vs Int column for row versioning in SQL Server

I want to apply data concurrency on some of tables in my SQL Server database. In order to achieve row versioning, I am thinking of adding an integer column named RowVersion, and increase the row value of the column when I update a row.

There is an other option: using timestamp column. When you use timestamp column, SQL Server automatically creates a unique value when the row was updated.

I want to know the advantages of these options. I think that inserting an int column to store row version is more generic way while inserting a timestamp column is SQL Server specific.

What is more, integer value of a row version is more human readable than timestamp column.

I want to know other advantages or disadvantages choosing integer column for row version field.

Thanks.

Upvotes: 3

Views: 2157

Answers (1)

Mike Nakis
Mike Nakis

Reputation: 61983

If you let SQL server do it for you, you have guaranteed atomicity for free. (Concurrent updates on the same table are guaranteed to produce different row versions.) If you roll your own row versioning scheme, you are going to have to do whatever it takes to guarantee atomicity by yourself.

Upvotes: 6

Related Questions