在 SQL Server 2005 中,是否有一种方法可以使用单个语句来拒绝删除行 在数据库所有用户的特定表中?
最佳答案
试试这个:
CREATE TRIGGER yourTriggerName ON YourTableName
INSTEAD OF DELETE
AS
ROLLBACK
RAISERROR('ERROR, DELETEs not permitted in YourTableName!!!',16,1)
RETURN
go
工作示例:
CREATE TABLE XYZ (RowID int)
INSERT XYZ VALUES(1)
INSERT XYZ VALUES(2)
go
CREATE TRIGGER yourTriggerName ON XYZ
INSTEAD OF DELETE
AS
ROLLBACK
RAISERROR('ERROR, DELETEs not permitted in XYZ!!!',16,1)
RETURN
go
delete XYZ
输出:
Msg 50000, Level 16, State 1, Procedure yourTriggerName, Line 6
ERROR, DELETEs not permitted in XYZ!!!
Msg 3609, Level 16, State 1, Line 1
The transaction ended in the trigger. The batch has been aborted.
关于sql - 如何拒绝所有用户删除表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3633012/