防止伺服器變更
公司也希望你能找到方法,避免員工誤刪資料庫。
經過詳細分析,你決定使用觸發程序來滿足這個需求。
此觸發程序會在有人嘗試刪除資料庫時進行復原(ROLLBACK)。
本練習屬於課程
在 SQL Server 建立與最佳化觸發程序
練習說明
- 建立一個名為
PreventDatabaseDelete的新觸發程序。 - 將觸發程序附加在伺服器層級。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
-- Create a trigger to prevent database deletion
CREATE TRIGGER ___
-- Attach the trigger at the server level
ON ___ ___
FOR DROP_DATABASE
AS
PRINT 'You are not allowed to remove existing databases.';
ROLLBACK;