开始使用免费开始使用

阻止删除表

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
    ___;
编辑并运行代码