读书人

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

发布时间: 2013-01-11 11:57:35 作者: rapoo

怎么在事物中获取未提交前的数据


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


我想在第二次查询到的版本号 与第一次查询到版本号一样,请问怎么设置查询呢?
[解决办法]
这个不行,只要改变过就会递增版本,事务无效

可以自定义版本,如用触发器等

读书人网 >SQL Server

热点推荐