SQL Server: starting DDL, managing table creation

I am using SQL Server 2008.

I create a DDL trigger as follows:

CREATE TRIGGER tName ON database FOR CREATE_TABLE as print 'A table has been created' 

Can I create a created table?

Something like inserted or deleted tables in regular triggers ?!

+4
source share
2 answers

Try the following:

 CREATE TRIGGER TRG_TABLES ON DATABASE AFTER CREATE_TABLE AS BEGIN SET NOCOUNT ON DECLARE @TABLE_NAME SYSNAME SELECT @TABLE_NAME = EVENTDATA().value('(/EVENT_INSTANCE/ObjectName)[1]','SYSNAME') ... END GO 
+3
source

I believe you need to extract it from CommandText in EventData() .

http://msdn.microsoft.com/en-us/library/ms187909.aspx

+1
source

Source: https://habr.com/ru/post/1402574/


All Articles