We help IT Professionals succeed at work.

rowversion (Transact-SQL)

Good morning, I'm reading about RowVersion (Transact-SQL)
http://msdn.microsoft.com/en-us/library/ms182776.aspx
but I do not understand: what is the ideal scenario for using this data type?
Comment
Watch Question

Guy Hengel [angelIII / a3]Billing Engineer
Most Valuable Expert 2014
Top Expert 2009

Commented:
this kind of field is used when you want to check for concurrent updates, so if since the SELECT, when you UPDATE/DELETE, the version has changed, you can notify the end-user that there has been a change between the select and the update/delete, eventually show the differences etc ...

Author

Commented:
Very interesting, could you show me an example
Billing Engineer
Most Valuable Expert 2014
Top Expert 2009
Commented:
what do you mean with "example"?

anyhow, say you do your SELECT primary_key, rowversion ... etc FROM yourtable WHERE priamry_key= 'ABC'
=> primary_key is ABC, and rowversion returns 1

when you then UPDATE, you would do like this:

UPDATE yourtable  
   SET ...
 WHERE primary_key = 'ABC'
   AND rowversion = 1

if that returns 0 records, either the primary key value would no longer exist, or rowversion has changed.
you can then rerun the above SELECT, and then you have 3 sets of data for the record:

the original one (first select)
the user update request data (user interface)
the current one (second select)

you could then ask the user to review the changes, and either force the update, review the data, or cancel, or partially update, or ...etc depending on how complex you want the user interface to be there ...




Author

Commented:
Just a question: to do this the user iterfaz should know the value of rv?
Article may offer some
Guy Hengel [angelIII / a3]Billing Engineer
Most Valuable Expert 2014
Top Expert 2009

Commented:
>: to do this the user iterfaz should know the value of rv?
exactly. which is known by the first SELECT

Author

Commented:
The original version of the row
Guy Hengel [angelIII / a3]Billing Engineer
Most Valuable Expert 2014
Top Expert 2009

Commented:
yes, exactly