简体   繁体   English

防止SQL Server中的DROP表

[英]Preventing DROP table in SQL Server

有没有办法以某种方式阻止SQL Server中的DROP TABLE,只需使用SSMS及其功能?

Don't give users permissions to drop tables. 不要授予用户删除表的权限。

You might think a DDL trigger can prevent this. 您可能认为DDL触发器可以防止这种情况发生。 It does, in a way: it lets the drop happen, then it rolls it back. 它确实在某种程度上:它让掉落发生,然后它回滚。 Which is not quite preventing it, but I suppose it might be good enough. 这并没有完全阻止它,但我想它可能已经足够好了。

Check this , There are two methods basically 检查一下 ,基本上有两种方法

The first one is based on creating a view on the table with option SCHEMABINDING. 第一个是基于使用选项SCHEMABINDING在表上创建视图。 When the SCHEMABINDING option is used the table cannot be modified in a way that will affect the view definition, as well as it cannot be dropped unless the view is dropped first. 使用SCHEMABINDING选项时,不能以影响视图定义的方式修改表,除非先删除视图,否则不能删除它。

The second method is using the new DDL triggers in SQL Server 2005. Defining a trigger for DROP_TABLE with rollback in the body will not allow dropping tables. 第二种方法是在SQL Server 2005中使用新的DDL触发器。在正文中使用回滚定义DROP_TABLE的触发器将不允许删除表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM