我想在主表“Table1”中进行插入,更新或删除时将行插入到审计表中 – 无论哪个列被更改/插入都无关紧要.我还想在插入,更新或删除时添加I,U或D.对于插入和删除,我正在检查inserted和deleted表中是否存在行.什么是接近更新的最佳方式.
CREATE TRIGGER [dbo].[tr_Table1_InsertUpdate_Table1History_Insert] ON [dbo].[Table1] FOR INSERT,DELETE,UPDATE AS BEGIN IF EXISTS(SELECT * FROM Inserted) BEGIN INSERT INTO Table1History(....,ModificationType) SELECT ...,'I' FROM Inserted END IF EXISTS(SELECT * FROM Deleted) BEGIN INSERT INTO Table1History(...,'D' FROM Deleted END END GO
请帮忙!