有非常简单的触发......
ALTER TRIGGER [dbo].[DEL_NOT_ALLOWED_ON_USER_TBL]
ON [dbo].[USER_TBL]
FOR DELETE AS
BEGIN
PRINT 'Sorry! - Delete Not Allowed!'
ROLLBACK TRANSACTION
INSERT INTO WHO_TRIED_TO_DELETE_TABLE
(DATE, DEL_TABLE_NAME, COMMENT)
VALUES (GETDATE(), 'USER_TBL', 'STOPPED DUE TO TRIGGER ON USR TABLE')
RETURN;
END
当有人试图执行如下语句时:
delete USER_TBL where 1 = 1 and user_id in ('john78rrt3458@yahoo.com') -- only 1 record found...
之后我在WHO_TRIED_TO_DELETE_TABLE
ROW_ID DATE DEL_TABLE_NAME COMMENT
32 10/23/2015 5:52:09 PM USER_TBL STOPPED DUE TO TRIGGER ON USR TABLE
31 10/23/2015 5:52:09 PM USER_TBL STOPPED DUE TO TRIGGER ON USR TABLE
有什么想法吗?
为什么触发器执行两次?
答案 0 :(得分:0)