CREATE TRIGGER 名1 ON t1
FOR INSERT
AS
insert t3 select id,name,account from inserted where id not in (select id from t3)
update t3 set account=t3.account+aa.account from inserted aa where t3.id=aa.id
CREATE TRIGGER 名2 ON t1
FOR update
AS
update t3 set account=t3.account+aa.account from inserted aa where t3.id=aa.id
CREATE TRIGGER 名3 ON t1
FOR delete
AS
update t3 set account=t3.account-aa.account from inserted aa where t3.id=aa.id

解决方案 »

  1.   

    CREATE TRIGGER 名1 ON t2
    FOR INSERT
    AS
    update t3 set account=t3.account-aa.account from inserted aa where t3.id=aa.id
    CREATE TRIGGER 名2 ON t2
    FOR update
    AS
    update t3 set account=t3.account+aa.account from deleted aa where t3.id=aa.id
    update t3 set account=t3.account-aa.account from inserted aa where t3.id=aa.id
    CREATE TRIGGER 名3 ON t2
    FOR delete
    AS
    update t3 set account=t3.account+aa.account from deleted aa where t3.id=aa.id
    CREATE TRIGGER 名1 ON t1
    FOR INSERT
    AS
    update t3 set account=t3.account+aa.account from inserted aa where t3.id=aa.id
    CREATE TRIGGER 名2 ON t1
    FOR update
    AS
    update t3 set account=t3.account-aa.account from deleted aa where t3.id=aa.id
    update t3 set account=t3.account+aa.account from inserted aa where t3.id=aa.id
    CREATE TRIGGER 名3 ON t1
    FOR delete
    AS
    update t3 set account=t3.account-aa.account from deleted aa where t3.id=aa.id
      

  2.   

    这么说就是在t1和t2表中都要写这样的触发器啦?
    你写的就是利用id这个字段来判断是吗?
    还有t3表上没有数据也可以吗?
      

  3.   

    这么说就是在t1和t2表中都要写这样的触发器啦?是!你把我第二次的放到查询分析器里仔细看看,再直接执行你写的就是利用id这个字段来判断是吗?
    是还有t3表上没有数据也可以吗?