Create TRIGGER [dbo].[tr_TableA_FieldA] ON [dbo].[TableA] FOR UPDATE AS begin if update(FieldA) begin insert into ChangeLog(EF_Type,EF_Context,ef_pguid) select 1, FieldA, AGuid -- inserted 表示新值 -- deleted 表示舊值 from deleted -- 當舊值不爲空 WHERE len(FieldA)>0 end end
當 TableA 的 FieldA 字段改變時,將其舊值插入到 ChangeLog 中。sql