问题
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 ?!
回答1:
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
回答2:
I believe you would need to extract it from the CommandText in the EventData()
.
http://msdn.microsoft.com/en-us/library/ms187909.aspx
来源:https://stackoverflow.com/questions/9797739/sql-server-ddl-trigger-controlling-table-creation