本文介紹了如何拒絕對(duì)所有用戶的表刪除的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
在 SQL Server 2005 中,是否有一種方法可以使用單個(gè)語句拒絕刪除行在數(shù)據(jù)庫的所有用戶的特定表中?
Within SQL Server 2005, is there a way, with a single statement, to deny delete on rows in a particular table for all users of the database?
推薦答案
試試這個(gè):
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.
這篇關(guān)于如何拒絕對(duì)所有用戶的表刪除的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!