请高手进来看看!!
我想用时间戳来解决在Read Committed下写覆盖的问题。
sql语句如下:
事务1:
use tcmanagement
begin tran
select * from tc where cno=0002
update tc set period=30 where cno=0002
commit tran
事务2:
use tcmanagement
begin tran
declare @t1 timestamp
declare @t2 timestamp
select @t1=t from tc where cno = 0002
select * from tc where cno=0002
select @t2=t from tc where cno = 0002
if (@t1=@t2)
begin
update tc set period=40 where cno=0002
end
else
begin
print '已更新过此数据!'
end
commit tran
假设我首先执行事务1中的
use tcmanagement
begin tran
select * from tc where cno=0002
再执行事务2中的
use tcmanagement
begin tran
declare @t1 timestamp
declare @t2 timestamp
select @t1=t from tc where cno = 0002
select * from tc where cno=0002
接着执行事务1中的
update tc set period=30 where cno=0002
commit tran
最后执行事务2的
select @t2=t from tc where cno = 0002
if (@t1=@t2)
begin
update tc set period=40 where cno=0002
end
else
begin
print '已更新过此数据!'
end
commit tran
但这时报错,说未定义变量@t1,@t2。这是因为局部变量问题。
那请问要怎么改?
如果改不了,那要怎样才能实现用时间戳来解决在Read Committed下写覆盖的问题啊?