如何在多用户情况下控制事务的完整性!有一个表,由于事务数据量大,而且需要在触发器中维护数据一致性,
要求每一条新增或更改的数据,
在事务没有提交前,
不能被引用含查询进行更新,
以避免引起数据的不一致性.
比如
create table a ( a int ,b varchar(30))--a用户
begin transaction test
insert into a(a,b)
select 1,'a001'--如何可以禁止其它用户在a用户在没有commit transaction test 前,不能查到此记录!
--同时,如要查询必须等待a用户提交事务或取消事务,也不可以更新新增加的记录
如 update a
set b = 'a002'
where b= 'a001'
要求每一条新增或更改的数据,
在事务没有提交前,
不能被引用含查询进行更新,
以避免引起数据的不一致性.
比如
create table a ( a int ,b varchar(30))--a用户
begin transaction test
insert into a(a,b)
select 1,'a001'--如何可以禁止其它用户在a用户在没有commit transaction test 前,不能查到此记录!
--同时,如要查询必须等待a用户提交事务或取消事务,也不可以更新新增加的记录
如 update a
set b = 'a002'
where b= 'a001'
如果不允许修改,则需要在事务开始,设置最严格的 SET transaction SERIALIZABLE LEVEL
set @error=0
begin tran
insert...
set @error=@error+@@error
update...
set @error=@error+@@error
if @error<>0
rollback
else
commit