sql server - Retrieving new rowversion after INSERT using @@DBTS - is it safe? -
it common practice pick newly created identity
of table using @@identity
variable after insert
.
is equality correct retrieve last rowversion
value following update
in similar manner using @@dbts
value?
for example:
if(object_id('xxx') not null) drop table xxx go create table xxx ( id int identity(1,1) primary key, name varchar(64) not null, rv rowversion ) go insert xxx(name) values ('apples'),('bananas'),('cranberries'),('dragon fruit'),('eggplant'),('fig'),('grape') go select * xxx go update xxx set name = 'chocolate' id = 3 print @@dbts go
now @@dbts
safe concurrent updates?
if connection performs insert , updates between update
, print
, end rowversion
of 'other' connection rather 1 our own update?
according msdn @@dbts
returns last-used timestamp value of current database
this means not thread safe.
you should not use @@identity
. @@identity
, scope_identity
return last identity value generated in table in current session. however, scope_identity
returns value within current scope; @@identity
not limited specific scope. @@identity
can example return wrong value if trigger gets executed on table identity column.
Comments
Post a Comment