How to use update trigger to update another table?

前端 未结 4 1016
星月不相逢
星月不相逢 2020-12-05 07:01

I am new to triggers and want to create a trigger on an update of a column and update another table with that value.

I have table1 with a year column and if the appl

4条回答
  •  天命终不由人
    2020-12-05 07:51

    You only need to update the records in table2 if the column intannualyear is involved. Also, this is an alternative UPDATE syntax across two tables from what Martin has shown

    IF UPDATE(intannualyear)
        UPDATE table2
        SET    annualyear = inserted.intannualyear
        FROM   inserted
        WHERE table2.id = inserted.id
    

提交回复
热议问题