Reasons for abandoning SQL triggers that insert data into other tables?

People with some authority in our company tell me that this is a "no-no database" for creating triggers in a database that change rows in another table.

I used this method to create the initial default configuration, automatically save audit logs and other things that would be a nightmare, to constantly maintain inside heterogeneous applications that connect to this database. For more than ten years, I read that this is an appropriate way to centralize the maintenance of communication restrictions and take responsibility for applications that interact with data.

So my BS meter gets attached to this. Am I missing something fundamentally wrong with this technique, which makes it a bad practice in general?

+5
source share
6 answers

If you are careful with the startup code, there is nothing wrong with it. Some people manage to bite a bad start code and then decide that the triggers are bad (although it was a bad trigger code that was the problem). They then generalize this as “never use triggers”.

Another problem is .......

, , , . , , . .

+8

. -, . db, , , ..

, .

.

0

, no-no. , , , ( ), - , ....

no-no , - .

0

, , goto . , "" , DML , , .

SQL Server. , , , . , . "", , DML, .

, , . , , - , .

0

, , , , AUDIT, . , , , " ", , , SP .

- "idiosyncractic" , -. , .

0

, " " - , " no-nos".

, . - , , , - .

- " " - , ; , . , , " " - , - . - , - , , .

There are problems that are best (or even only) solved with triggers - forced referential integrity is a classic. There are problems that are often solved with triggers that make me nervous - especially when they reflect business rules or using an audit table. There are problems that, in my opinion, are too close to the trigger caused by the triggers, for example, calculations in the business domain (for example, calculating the amount of tax to be sold).

0
source

All Articles