資料庫觸發器,禁止DDL操作

zping發表於2016-01-18
CREATE TRIGGER [Object_Change_Trigger_DDL] ON DATABASE
FOR ALTER_TABLE,DROP_TABLE,CREATE_TABLE,CREATE_INDEX,ALTER_INDEX, DROP_INDEX  
AS
DECLARE @EventData AS XML;
SELECT @EventData = EVENTDATA();
IF @EventData.value('(/EVENT_INSTANCE/LoginName)[1]','varchar(150)') NOT IN (
'uws_M_ApricotMDM_dev'
,'Us_wangdan_temp'
,'NT AUTHORITY\SYSTEM'
,'NT SERVICE\MSSQLSERVER'
,'WIN-6RNHUPNK4OJ\Administrator'
,'NT SERVICE\SQLSERVERAGENT'
,'bl_un'
) 
  BEGIN
   --RAISERROR ('建立,修改,刪除表的許可權已收回,如有問題請聯絡DBA!', 16, 1)     
   ROLLBACK
  END


GO

ENABLE TRIGGER [Object_Change_Trigger_DDL] ON DATABASE
GO

 

相關文章