Comments on: SQL Database Triggers https://thomaslarock.com/2009/03/sql-database-triggers/ Thomas LaRock is an author, speaker, data expert, and SQLRockstar. He helps people connect, learn, and share. Along the way he solves data problems, too. Tue, 30 Jun 2015 21:38:00 +0000 hourly 1 https://wordpress.org/?v=6.7.1 By: ThomasLaRock https://thomaslarock.com/2009/03/sql-database-triggers/#comment-12930 Tue, 30 Jun 2015 21:38:00 +0000 http://sqlbatman.com/?p=1063#comment-12930 In reply to Stephen.

Thanks!

]]>
By: Stephen https://thomaslarock.com/2009/03/sql-database-triggers/#comment-12929 Tue, 30 Jun 2015 21:30:00 +0000 http://sqlbatman.com/?p=1063#comment-12929 If you’re using triggers, you’re probably doing it wrong.

That’s what I’ve come to know. The more I’ve worked in this field, the more I’ve learned to use my bad-code divining rods and there’s no surer way to make them cross than to come across some triggers (‘cept maybe some cursors).

If you’re using triggers to enforce referential integrity, you’re doing it wrong.
If you’re using triggers to ensure ‘power users’ don’t screw up the data, you’re WAY doing it wrong.
Use stored procedures, roles, and permissions to ensure that ‘power users’ don’t screw up the data. Use foreign keys and good schema design to enforce referential integrity.

Use Triggers to ride off into the sunset.

]]>
By: ThomasLaRock https://thomaslarock.com/2009/03/sql-database-triggers/#comment-12926 Mon, 29 Jun 2015 16:46:00 +0000 http://sqlbatman.com/?p=1063#comment-12926 In reply to SgtWilko.

Ha! Thanks for the comment, I didn’t know about that tool. I will have to take a look the next time I have a chance.

]]>
By: SgtWilko https://thomaslarock.com/2009/03/sql-database-triggers/#comment-12925 Mon, 29 Jun 2015 12:35:00 +0000 http://sqlbatman.com/?p=1063#comment-12925 Try using the Redgate SQL search tool.

If you have a table where the values are being changed, a quick search with the Redgate search tool will indicate everywhere that the table is referenced (including all triggers, procedures, functions and views.)

Makes part of your complaint about being unable to see what’s manipulating your data void.

The rest I can understand 🙂

]]>
By: ThomasLaRock https://thomaslarock.com/2009/03/sql-database-triggers/#comment-12923 Mon, 29 Jun 2015 02:31:00 +0000 http://sqlbatman.com/?p=1063#comment-12923 In reply to Bill Butler.

Thanks for the comment Bill. Triggers do have a place, I just wish that our tools made it easier to understand that they were in use.

]]>
By: Bill Butler https://thomaslarock.com/2009/03/sql-database-triggers/#comment-12922 Sun, 28 Jun 2015 20:26:00 +0000 http://sqlbatman.com/?p=1063#comment-12922 I agree with all of the reasons why triggers are bad. I do use them for auditing. But I also have a real use case where I have found them invaluable and I will continue to use them. I have had many engagements over the years where the client (i.e. power user) is in direct control of their database, and as such they reach in and perform data modifications outside of the application we develop–you can only admonish them so much. Because of this I use triggers to keep denormalized values up to date specifically balances, as in the case of on-hand inventory with respect to inventory transactions or customer balances with respect to AR transactions. If they decide to delete a transaction (or a 1000), I don’t want the headache of having to figure out why they are now telling me that the inventory valuation report is wrong.

]]>
By: ThomasLaRock https://thomaslarock.com/2009/03/sql-database-triggers/#comment-12914 Sat, 27 Jun 2015 15:57:00 +0000 http://sqlbatman.com/?p=1063#comment-12914 In reply to Steve Naidamast.

Thanks for the comment Steve. You are correct, it’s the extra layer of ambiguity. In my shop I was an advocate for not adding in such layers unless absolutely necessary.

]]>