Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fire trigger on DISABLE TRIGGER

There's a safety trigger that blocks all SQL DDL events (ALTER/DROP/CREATE etc.) on a production database instance.

For deployments you'd do DISABLE TRIGGER and then ENABLE TRIGGER when done.

I'd like an Operator to be notified (EXEC sp_notify_operator ...) when the safety trigger is DISABLED/ENABLED. They don't appear to be DDL events and I can't add an UPDATE/DELETE trigger on sys.triggers either. Any ideas?

like image 292
Serguei Avatar asked Dec 04 '25 19:12

Serguei


1 Answers

Since you're already "protected" so to speak from DDL statements being executed, you could add another database trigger looking for DDL events that calls a procedure to notify an operator. You might need another layer of management though - maybe something to queue the notifications - so that it doesn't become too spammy. I could envision changes being rolled out and receiving 100+ email notices...yuck.

CREATE TRIGGER DatabaseDDLNotices
ON DATABASE FOR DDL_DATABASE_LEVEL_EVENTS
AS BEGIN
  -- place something into a queue to be batched later
END;

In my opinion this also has the nice side effect of keeping notification logic and DDL prevention logic separated.

like image 147
Yuck Avatar answered Dec 06 '25 08:12

Yuck



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!