Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Server RowVersion

Quick question Re: Implementation of RowVersion.

I am looking to include it in my next database (Designing it now) and I am pondering 2 different ways:

  1. RowVersion row in all tables
  2. A separate RowVersion table which has the ID of the table as a foreign key and linked to it.

Anyone tried this? If so what pitfalls or pro's did you experience?

I will be using LINQ to access the data using C# 2008 and SQL Server 2008.

Thanks,

James

like image 795
Darbio Avatar asked Jan 08 '10 04:01

Darbio


People also ask

What is Rowversion in SQL Server?

rowversion is generally used as a mechanism for version-stamping table rows. The storage size is 8 bytes. The rowversion data type is just an incrementing number and does not preserve a date or a time. To record a date or time, use a datetime2 data type.

What is SQL Server change tracking?

SQL Server Change Tracking is a synchronous tracking mechanism, in which the changes information will be available directly once the DML change is committed, without the need for a delay while reading the changes from the Transaction Log file, such as the Change Data Capture asynchronous mechanism.

How do I do a timestamp in SQL?

MySQL TIMESTAMP() FunctionThe TIMESTAMP() function returns a datetime value based on a date or datetime value. Note: If there are specified two arguments with this function, it first adds the second argument to the first, and then returns a datetime value.


1 Answers

If you are using LINQ to SQL then it is a good practice to include a timestamp / rowversion column for each entity table, as this allows LINQ to use optimistic concurrency very easily and results in slightly better performance for updates (as LINQ only has to query the timestamp column and does not have to compare other columns for changes).

So go for the first option. The second option is a non-starter, really.

like image 158
Sam Avatar answered Sep 28 '22 05:09

Sam