2009年9月2日 星期三

用 Trigger 寫 Table log (Insert,update,delete) 的簡單範例

CREATE TRIGGER [tri_TABLE1_INS] ON [TABLE1]
FOR INSERT
AS
INSERT INTO TABLE1_LOG
SELECT 'INS', GETDATE(), * FROM INSERTED
GO

CREATE TRIGGER [tri_TABLE1_UPD] ON [TABLE1]
FOR UPDATE
AS
INSERT INTO TABLE1_LOG
SELECT 'UPD', GETDATE(), * FROM INSERTED
GO

CREATE TRIGGER [tri_TABLE1_DEL] ON [TABLE1]
FOR DELETE
AS
INSERT INTO TABLE1_LOG
SELECT 'DEL', GETDATE(), * FROM DELETED
GO

沒有留言:

張貼留言