防止刪除資料表
Fresh Fruit Delivery 想要防止一般員工從資料庫中刪除資料表。
本練習屬於課程
在 SQL Server 建立與最佳化觸發程序
練習說明
- 建立一個新的觸發程序
PreventTableDeletion,用來防止刪除資料表。 - 這個觸發程序應該回復觸發的陳述式,如此刪除動作就不會發生。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
-- Add a trigger to disable the removal of tables
CREATE TRIGGER ___
ON DATABASE
FOR ___
AS
RAISERROR ('You are not allowed to remove tables from this database.', 16, 1);
-- Revert the statement that removes the table
___;