日期:2014-05-18  浏览次数:20510 次

求个sql触发器
当表a的 aid行的a1列由1update为5时触发 
update 表B where bid=aid

------解决方案--------------------
判斷原值deleted 表
判斷修改之後的值inserted表

------解决方案--------------------
SQL code

--大致如下,自行补充要更新表b的那个字段,及表b与表a的关联关系
create tirgger tupdate_a on a
for update 
as
if update(a1) and exists(select 1 from inserted,deleted where inserted.aid = deleted.aid
        and inserted.a1 = 1 and deleted.a1 = 5)
begin
    update 表B
    set --自已补充
    from  inserted,deleted
    where inserted.aid = deleted.aid
    and inserted.a1 = 1 and deleted.a1 = 5
    and inserted.aid = 表B.bid
end