SQL Server : DDL trigger, controlling table creation
-
25-05-2021 - |
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 ?!
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()
.
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow