积极答复者
触发器会不会并发?

问题
-
create table tTest1(id int identity(1,1),Val int)
gocreate table tTest2(id int identity(1,1),Val int)
goinsert tTest1 values(0)
insert tTest2 values(0)
gocreate trigger [uTest1] on [tTest1] for update as
begin
declare @tmp int
select @tmp=Val+(select Val from inserted) from tTest2--用临时变量应该会并发?
update tTest2 set Val=@tmp
end
go--连接一
declare @counter int
set @counter=50000
while @counter>0
begin
update tTest1 set Val=1,@counter=@counter-1
end
go--连接二
declare @counter int
set @counter=50000
while @counter>0
begin
update tTest1 set Val=-1,@counter=@counter-1
end
在查询分析器同时运时连接一、连接二,结果tTest2表的Val=0,是不是触发器不会并发?如果不会并发,那么是用了什么锁呢?
答案
全部回复
-
触发器当然是顺序执行。至于上什么样的锁,取决于你的事务的隔离级别(tracsaction isolation level)。 你的两个连接分别是两个事务,缺省的隔离级别是read committed. 请参考:http://msdn.microsoft.com/en-us/library/ms189122.aspx
This posting is provided "AS IS" with no warranties, and confers no rights.