I got this sample code. It works fine with all T-SQL code but if I drop a table in SSMS by mouse clicks the event is not tracked – the question is why?
-- create the table to store the events
CREATE TABLE dbo.CREATE_TABLE_LOG (
eventTime datetime
, eventOwner nvarchar(100)
, eventTSQL nvarchar(3000)
)
GO
-- create the DDL trigger
CREATE TRIGGER DDLTrigger_CreateTable ON DATABASE FOR create_table, alter_table, drop_table
AS
DECLARE @data XML
SET @data = EVENTDATA()
INSERT INTO CREATE_TABLE_LOG
VALUES (
GETDATE()
, CURRENT_USER
, @data.value('(/EVENT_INSTANCE/TSQLCommand/CommandText)[1]',
'nvarchar(1000)')
)
GO
I’ve checked on both SQL Server 2005 and SQL Server 2008, given the logging table and the DDL trigger provided, it has correctly recorded the drop, regardless of how I dropped it in SSMS.
Can you provide the exact menu / context menu commands you are using, and double check that you are not dropping the table in 1 database, and reading the log table in another (like you accidently created a duplicate log table in master).