当前位置: 代码迷 >> Sql Server >> 如何在事物中获取未提交前的数据
  详细解决方案

如何在事物中获取未提交前的数据

热度:24   发布时间:2016-04-24 23:55:57.0
怎么在事物中获取未提交前的数据

if OBJECT_ID('testtb') is not null
drop table testtb
go

create table testtb
(id int identity(1,1) not null,
 iQty dec(18,2),
 Version timestamp
 )
 
insert into testtb (iQty)
select 12


begin tran 
select CAST(Version as bigint) from testtb 
where id=1 
update testtb set iQty=12 where id=1
select CAST(Version as bigint) from testtb 
where id=1 
commit tran 


我想在第二次查询到的版本号 与第一次查询到版本号一样,请问怎么设置查询呢?

------解决方案--------------------
这个不行,只要改变过就会递增版本,事务无效

可以自定义版本,如用触发器等
  相关解决方案