Can we get a license for DDL Triggers?

4

December 14, 2015 by Kenneth Fisher

There are several types of triggers.

  • Logon triggers – Fired when someone tries to connect to the instance.
  • DML triggers – Fired after a DML statement. INSERT, UPDATE and DELETE statements.
  • DDL triggers – Fired after a DDL statement. For example CREATE, ALTER, DROP, GRANT, DENY, and REVOKE.

 
All triggers require careful thought before implementing them. Logon triggers in particular are dangerous because they can stop anyone from being able to connect to the instance and it can take some extra work to get around them if they run amok. DML triggers are next on my be careful when using list. The problem is that these guys fire the most frequently. INSERT, UPDATE, and DELETE statements are the lifeblood of an OLTP system, coming only only behind SELECT statements in frequency and importance. Because of this any problem with a DML trigger can be compounded dramatically. They’ve been around for a while and they are heavily documented so there are lot’s of examples on how to get this type of trigger right and we don’t see a lot of absolute failures. The bane of the DML trigger is performance. A small performance issue in a DML trigger can bring a system to a grinding halt.

So now we come down to DDL triggers. These are the least dangerous type of trigger. Of course this is kind of like saying my $10k server is cheap. It’s all about perspective right? DDL triggers generally only affect developers and DBAs not users. I guess it could affect a user, but if your users are running CREATE/ALTER statements for example, then you are probably doing something wrong. Performance issues aren’t really an issue here either. No one cares if a CREATE TABLE statement takes an extra 30 seconds or so. DDL triggers are newer and while they are still reasonably well documented they are more complicated (more commands can be covered) and so mistakes are easier to make. The bane of the DDL trigger is the unexpected code path that causes your trigger to fail. The real down side is that if you aren’t the one who wrote the trigger it can be a real pain to track down why your reindex process is failing. (No, I’m not bitter at all. No really, I actually enjoy that kind of thing. But I’m rather weird.)

So here is my call to action. We have drivers licenses. How about we create a trigger license? You have to pass a test before you are allowed to put a trigger into production. And since DDL triggers are less dangerous (at least by comparison) and so most likely to be used carelessly let’s start with those.

4 thoughts on “Can we get a license for DDL Triggers?

  1. Scott says:

    I fully agree! These things are dangerous in the wrong hands.

  2. […] tend to feel that a lot of people who use triggers don’t really understand them. That said, every now and again you have to deal with them. And in particular (for this post) you […]

  3. […] Can we get a license for DDL triggers? […]

  4. […] I’ve done more than a few rants in my time blogging. One more should be a piece of cake. Interestingly the day I read the invite we were discussing a POC (proof of concept) being done at my company. And me being me I started a bit of a rant, realized what I was doing, and that I was ranting at people that agreed with me and shut up. But, it did give me a good idea for this post 😁. […]

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Enter your email address to follow this blog and receive notifications of new posts by email.

Join 6,758 other subscribers

Follow me on Twitter

Archives

ToadWorld Pro of the Month November 2013