Create Trigger Trigger_t1_Update On table1
For Update
As
If Update(字段2) Or Update(字段3) Or Update(字段4) or Update(字段7) or Update(字段8)
Begin
Update table2
Set 字段2=I.字段2,字段3=I.字段3,字段4=I.字段4,字段7=I.字段7,字段8=I.字段8
From Inserted I,Deleted D
Where 字段2=d.字段2 And 字段3=D.字段3 And 字段4=D.字段4 And 字段7=D.字段7 And 字段8=D.字段8
End
For Update
As
If Update(字段2) Or Update(字段3) Or Update(字段4) or Update(字段7) or Update(字段8)
Begin
Update table2
Set 字段2=I.字段2,字段3=I.字段3,字段4=I.字段4,字段7=I.字段7,字段8=I.字段8
From Inserted I,Deleted D
Where 字段2=d.字段2 And 字段3=D.字段3 And 字段4=D.字段4 And 字段7=D.字段7 And 字段8=D.字段8
End
For Update
As
If Update(字段2) Or Update(字段3) Or Update(字段4) or Update(字段7) or Update(字段8)
Begin
Update table2
Set 字段2=I.字段2,字段3=I.字段3,字段4=I.字段4,字段7=I.字段7,字段8=I.字段8
From Inserted I,table2 D
Where 字段2=d.字段2 And 字段3=D.字段3 And 字段4=D.字段4 And 字段7=D.字段7 And 字段8=D.字段8
End
更新前的信息存放在Deleted表里
更新后的信息存放在Inserted表里
更新一个记录=先删除这条记录再插入一条新的记录