Question

I'm using SQL Server 2008.

I'm creating a DDL trigger like this:

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

Can I get that table that has been created !?

Something like inserted or deleted in the normal table triggers ?!

Était-ce utile?

La solution

Try this:

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

Autres conseils

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

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

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top