Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I know if a database trigger is DROP_TABLE or ALTER_TABLE?

If I create a database trigger in SQL Server 2008 which triggers on both DROP_TABLE and ALTER_TABLE, how do I determine whether this is a DROP or an ALTER?

like image 652
Tim Avatar asked Dec 04 '25 13:12

Tim


1 Answers

Inside the trigger you can test

SELECT EVENTDATA().value('(/EVENT_INSTANCE/EventType)[1]','sysname')

It will be DROP_TABLE or ALTER_TABLE

Documentation for EVENTDATA

like image 51
Martin Smith Avatar answered Dec 07 '25 02:12

Martin Smith



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!