ddl 触发
USE Test;
GO
CREATE TABLE alter_log (PostTime datetime, DB_User nvarchar(100), Event nvarchar(100),dbName nvarchar(32), TSQL nvarchar(2000),EventData xml);
GO
CREATE TRIGGER ddl_alter_log
ON all server
after CREATE_TABLE,DROP_TABLE,ALTER_TABLE,CREATE_PROCEDURE,ALTER_PROCEDURE,DROP_PROCEDURE
AS
INSERT into Test..alter_log
(PostTime, DB_User, Event, dbName,TSQL)
VALUES
(GETDATE(),
CONVERT(nvarchar(100), CURRENT_USER),
EVENTDATA().value( '(/EVENT_INSTANCE/EventType)[1] ', 'nvarchar(100) '),
DB_NAME(),
EVENTDATA().value( '(/EVENT_INSTANCE/TSQLCommand)[1] ', 'nvarchar(2000) ') )
GO
ENABLE TRIGGER ddl_alter_log ON ALL SERVER
这个有什么问题吗,该怎么处理呢?
------解决方案--------------------老大,尝试的早点。估计都得靠自己了。
一个星星呢!呵呵。
等你解决出来我copy 一下!!!
------解决方案--------------------CREATE TRIGGER ddl_alter_log
ON database
after CREATE_TABLE,DROP_TABLE,ALTER_TABLE,CREATE_PROCEDURE,ALTER_PROCEDURE,DROP_PROCEDURE
AS
INSERT into Test..alter_log
(PostTime, DB_User, Event, dbName,TSQL)
VALUES
(GETDATE(),
CONVERT(nvarchar(100), CURRENT_USER),
EVENTDATA().value( '(/EVENT_INSTANCE/EventType)[1] ', 'nvarchar(100) '),
DB_NAME(),
EVENTDATA().value( '(/EVENT_INSTANCE/TSQLCommand)[1] ', 'nvarchar(2000) ') )
GO
------解决方案--------------------ON all server
after CREATE_TABLE,DROP_TABLE,ALTER_TABLE,CREATE_PROCEDURE,ALTER_PROCEDURE,DROP_PROCEDURE
-----------------------------------------------
这些事件是: 数据库作用域的 DDL 语句
------解决方案--------------------作用域
数据库作用域的 DDL 语句
CREATE_APPLICATION_ROLE(应用于 CREATE APPLICATION ROLE 语句和 sp_addapprole。如果创建新架构,则此事件也触发 CREATE_SCHEMA 事件。)
ALTER_APPLICATION_ROLE(应用到 ALTER APPLICATION ROLE 语句和 sp_approlepassword。)
DROP_APPLICATION_ROLE(应用到 DROP APPLICATION ROLE 语句和 sp_dropapprole。)
CREATE_ASSEMBLY
ALTER_ASSEMBLY
DROP_ASSEMBLY
ALTER_AUTHORIZATION_DATABASE(应用到 sp_changedbowner,在指定 ON DATABASE 时,还可应用到 ALTER AUTHORIZATION 语句。)
CREATE_CERTIFICATE
ALTER_CERTIFICATE
DROP_CERTIFICATE
CREATE_CONTRACT
DROP_CONTRACT
GRANT_DATABASE
DENY_DATABASE
REVOKE_DATABASE
CREATE_EVENT_NOTIFICATION
DROP_EVENT_NOTIFICATION
CREATE_FUNCTION
ALTER_FUNCTION
DROP_FUNCTION
CREATE_INDEX
ALTER_INDEX
DROP_INDEX
CREATE_MESSAGE_TYPE
ALTER_MESSAGE_TYPE
DROP_MESSAGE_TYPE
CREATE_PARTITION_FUNCTION
ALTER_PARTITION_FUNCTION
DROP_PARTITION_FUNCTION
CREATE_PARTITION_SCHEME
ALTER_PARTITION_SCHEME
DROP_PARTITION_SCHEME
CREATE_PROCEDURE
ALTER_PROCEDURE
DROP_PROCEDURE
CREATE_QUEUE
ALTER_QUEUE
DROP_QUEUE
CREATE_REMOTE_SERVICE_BINDING
ALTER_REMOTE_SERVICE_BINDING
DROP_REMOTE_SERVICE_BINDING