ALTER TRIGGER [dbo].[T_Update_Bgd]
ON [dbo].[T_AB] for update
AS
BEGIN
if update(BGD)
begin
update c set c.status='Y'
from inserted a,T_C c
where a.YB=c.YW
and isnull(a.BGD,'')<>''
update c set c.qptime=GETDATE()
from inserted a, dbo.T_AB c
where a.bgd=c.bgd
end
end如何修改这个触发器能够更好的避免死锁?
当然了,可以在程序里一次性写好语句更新,这个不管,只是谈论Trigger
谢谢
ON [dbo].[T_AB] for update
AS
BEGIN
if update(BGD)
begin
update c set c.status='Y'
from inserted a,T_C c
where a.YB=c.YW
and isnull(a.BGD,'')<>''
update c set c.qptime=GETDATE()
from inserted a, dbo.T_AB c
where a.bgd=c.bgd
end
end如何修改这个触发器能够更好的避免死锁?
当然了,可以在程序里一次性写好语句更新,这个不管,只是谈论Trigger
谢谢
ON [dbo].[T_AB] for update
AS
BEGIN
if update(BGD)
begin
update c set c.status='Y'
from inserted a,T_C c
where a.YB=c.YW
and isnull(a.BGD,'')<>''update c set c.qptime=GETDATE()
from inserted a, dbo.T_AB c
where a.bgd=c.bgd
end
end
死锁原因确定是这个吗??
其他地方更新时也先写T——C的再写T——A的,顺序一致
当update T_AB 中的BGD栏位时再更新到T_C中的状态。。别的地方都没有用事务,而且两个表会并发。是否先更新本身T_AB 再更新T_C会好点?