WEB开发网
开发学院数据库MSSQL Server SQL Server 2005中DDL触发器的实现 阅读

SQL Server 2005中DDL触发器的实现

 2010-04-28 15:42:55 来源:WEB开发网   
核心提示:接下来,我们尝试如下的操作:ALTER TABLE MYTABLE ADD X INT结果如下,SQL Server 2005中DDL触发器的实现(2),出现错误提示ALTER TABLE MYTABLE ADD X INT(1 row(s) affected)You are not allowed to CREATE

接下来,我们尝试如下的操作:

ALTER TABLE MYTABLE ADD X INT

结果如下,出现错误提示

ALTER TABLE MYTABLE ADD X INT
(1 row(s) affected)
You are not allowed to CREATE,ALTER and DROP any Tables and Procedures
Msg 3609, Level 16, State 2, Line 1
The transaction ended in the trigger. The batch has been aborted.

再执行DROP的操作,同样触发警告

DROP TABLE MYTABLE
(1 row(s) affected)
You are not allowed to CREATE,ALTER and DROP any Tables and Procedures
Msg 3609, Level 16, State 2, Line 1
The transaction ended in the trigger. The batch has been aborted.

因为我们的触发器规定了不能使用CREATE_TABLE、DROP_TABLE、ALTER_TABLE、CREATE_PROCEDURE、ALTER_PROCEDURE、DROP_PROCEDURE等操作。 如果我们要关掉这个触发器,可以这样做:

DISABLE TRIGGER STOP_DDL_ON_TABLE_AND_PROC ON DATABASE

当然,我们要对整个服务器采取策略的话,也是很简单的,和上面的方法大致相同只不过将on database的参数改为on server,比如

CREATE TRIGGER STOP_DDL_on_Table_and_PROC
ON ALL SERVER
FOR CREATE_DATABASE,ALTER_DATABASE,DROP_DATABASE
AS
PRINT 'You are not allowed to CREATE,ALTER and DROP any Databases'
ROLLBACK;

上一页  1 2 

Tags:SQL Server DDL

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接