Database Triggers

Posted by Jeff Ledbetter on 20-Mar-2017 13:00

Hi.

What is the "recommended" usage of database triggers in OE applications these days?

Are they still okay to use, or is it considered ancient, legacy, bad-idea, etc.? 

Posted by Jeff Ledbetter on 20-Mar-2017 13:59

Thank you all for input. It all matches our internal dialog on some level.

"..that may imply that you have multiple creates of a table in various portions of the application"

Not all applications are perfect. :)

All Replies

Posted by Tim Kuehn on 20-Mar-2017 13:06

They have their place and can be used to implement application / db-wide behavior that can't be done any other way.

Did you have any specific concerns?

Posted by Jeff Ledbetter on 20-Mar-2017 13:09

Hi Tim. No specific concern; just curious if they were still considered appropriate to use or if one should always code the logic needed into the applications.

Posted by Mike Fechner on 20-Mar-2017 13:10

What is it that can’t be done any other way?

Posted by jquerijero on 20-Mar-2017 13:11

You can still use it for database integrity cases like cascading updates and deletes.

Posted by Tim Kuehn on 20-Mar-2017 13:12

The main use case I ran into was capturing data changes across the application, applying some business logic to identify and capture the transactions, send the changes to related sites, apply the changes while applying more business logic.

Without db triggers, there was no way this project could've been economically completed.

Posted by Mike Fechner on 20-Mar-2017 13:14

I personally consider them o.k. for basic RI (delete cascade, delete restrict, etc.) – when the application is not based on a framework which supports RI in the core data access classes.
 
I tend to avoid any business logic in them.
 

Posted by Mike Fechner on 20-Mar-2017 13:18

“Without db triggers, there was no way this project could've been economically completed.”

OK – your first statement sounded a lot like you were suggesting certain ABL capabilities only exist in triggers.
 
This statement now sounds much more like it had to be done in a certain way due to the structure of the legacy application code base.
 

Posted by jquerijero on 20-Mar-2017 13:21

I believe it is replication use case, which is most appropriate inside the table triggers.

Posted by Jeff Ledbetter on 20-Mar-2017 13:23

I was thinking along the lines of assigning unique key values (i.e. guid values). In theory, is that an appropriate use-case for a trigger or should it be in application code?

Posted by Peter Judge on 20-Mar-2017 13:28

I’d consider that in a create trigger.
 
If you are saving data from temp-tables and you have parent/child relationships in that data, then you may need to reconsider (since you have a key there anyway).
 

Posted by jquerijero on 20-Mar-2017 13:30

We do use triggers in that manner. Although it makes it tricky synchronizing the temp-table after creating a record which now have the valid GUID.

Posted by Mike Fechner on 20-Mar-2017 13:34

In which case the value from the create trigger would most likely be overwritten with the data from the temp-tables (external system). So that parent/child relation should remain intact.
Von: Peter Judge [mailto:bounce-pjudge@community.progress.com]
Gesendet: Montag, 20. März 2017 19:29
An: TU.OE.Development@community.progress.com
Betreff: RE: [Technical Users - OE Development] Database Triggers
 
Update from Progress Community
 
I’d consider that in a create trigger.
 
If you are saving data from temp-tables and you have parent/child relationships in that data, then you may need to reconsider (since you have a key there anyway).
 

View online

 

You received this notification because you subscribed to the forum.  To unsubscribe from only this thread, go here.

Flag this post as spam/abuse.

 

Posted by Tim Kuehn on 20-Mar-2017 13:38

[quote user="Mike Fechner"]

“Without db triggers, there was no way this project could've been economically completed.”

OK – your first statement sounded a lot like you were suggesting certain ABL capabilities only exist in triggers.
 
This statement now sounds much more like it had to be done in a certain way due to the structure of the legacy application code base.

[/quote]

It was an question of capturing all data changes regardless of where they were made, and maintaining that capability regardless of who was maintaining the code down the line.

Triggers were the only technology that provided that capability. 

Posted by jmls on 20-Mar-2017 13:40

I have to say that I do not like or use db triggers - I was bitten by the fact that they are not run when executing SQL .

If you are looking to use create triggers, that may imply that you have multiple creates of a table in various portions of the application - something in itself could be considered "sub-optimal" as it would mean that any change to the creation code would require multiple changes to the source.

Just my 0.01p* worth

* adjusted after currency devaluation

Posted by Peter Judge on 20-Mar-2017 13:42

Ah, so you’re saying do both and then you don’t get hurt in the case where a single-table-create doesn’t previously assign values?
 

Posted by marian.edu on 20-Mar-2017 13:46

Only there is also a disable triggers statement and ‘everywhere' does not include the SQL engine (JDBC/ODBC) so I would say it’s probably time for Progress to actually become a relational database and add a long due support for foreign keys inside the database server instead of pretending this can be done using triggers (running on client space).


Marian Edu

Acorn IT 
+40 740 036 212

Posted by Mike Fechner on 20-Mar-2017 13:46

Yes.
Von: Peter Judge [mailto:bounce-pjudge@community.progress.com]
Gesendet: Montag, 20. März 2017 19:43
An: TU.OE.Development@community.progress.com
Betreff: RE: [Technical Users - OE Development] Database Triggers
 
Update from Progress Community
 
Ah, so you’re saying do both and then you don’t get hurt in the case where a single-table-create doesn’t previously assign values?
 

View online

 

You received this notification because you subscribed to the forum.  To unsubscribe from only this thread, go here.

Flag this post as spam/abuse.

 

Posted by Thomas Mercer-Hursh on 20-Mar-2017 13:47

I have always felt that the core flaw of db triggers was that it put the logic of record creation, modification, and deletion in two different places -- partly in the trigger and partly in the application code.  There is nothing in either to tell you what is happening in the other one.  A properly designed modern application is going to have these actions centralized in a component responsible for those actions so there is one place to check to see what is happening and one place to modify if changes are needed.  DB triggers get in the way of that goal.

Posted by jmls on 20-Mar-2017 13:52

Oh dear. I agree with the Doctor. Have I been assimilated ?

Posted by Mike Fechner on 20-Mar-2017 13:56

We all have been partly assimilated 😊 See my earlier comment

Posted by Jeff Ledbetter on 20-Mar-2017 13:59

Thank you all for input. It all matches our internal dialog on some level.

"..that may imply that you have multiple creates of a table in various portions of the application"

Not all applications are perfect. :)

Posted by Thomas Mercer-Hursh on 20-Mar-2017 15:27

Not all applications are perfect, but this should not be used as an excuse to just do what is expedient or convenient.  We should understand what is better and constantly strive to incorporate that into the application whenever possible.

Posted by Jeff Ledbetter on 20-Mar-2017 15:31

Agreed. It was a theoretical question that came up while updating code (within the app) to set the field value.

Posted by Patrick Tingen on 21-Mar-2017 01:40

[quote user="Thomas Mercer-Hursh"]

Not all applications are perfect, but this should not be used as an excuse to just do what is expedient or convenient.  We should understand what is better and constantly strive to incorporate that into the application whenever possible.[/quote]

You are absolutely right and this is exactly what I told management here. It was a few seconds before they started laughing and walked away.

Did I say something weird?

Posted by Frank Meulblok on 21-Mar-2017 05:41

[quote user="Patrick Tingen"]

Thomas Mercer-Hursh

Not all applications are perfect, but this should not be used as an excuse to just do what is expedient or convenient.  We should understand what is better and constantly strive to incorporate that into the application whenever possible.

You are absolutely right and this is exactly what I told management here. It was a few seconds before they started laughing and walked away.

Did I say something weird?

[/quote]

Just sounds like they made a different 2 out of 3 picks from "fast, good, cheap" than you would...

This thread is closed