Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

prevent trigger fire if caused by cascading

Status
Not open for further replies.

Warwick32

Programmer
May 19, 2011
2
AU
I've been reviewing a lot of data auding options, and it seems that generic auditing triggers are mostly horrendous to read/understand/maintain and/or have performance problems.

I've nearly finished developing a generic stored proceedure that can add a table specific trigger to each table, for all columns. This has the advantage that the code that generates the trigger is generic, but the trigger itself is specific, and hence is high performance. It can also be re-run periodically if the table schema changes. I will post it here when done.

However, I don't want to log updates (or deletes, but thats another topic) where they are caused by cascading from a parent table, and am having trouble identifying these. It's not a "recursive_trigger" issue as the update (or delete) occurs as a result of a cascade (recursive triggers are off anyway).

Any advise on how to exit a trigger if it is the result of a cascade would be much appreciated.

Warwick
 
Hello,

Thankyou for that suggestion. It looked promising in that I thought I could flag a value when the trigger on the parent table fired, and check it on the child table trigger, however it turns out that the child table triggers (update, delete) get triggered first! Therefore I still can't identify if they have cascaded.

I can't rely on flagging it in a stored proceedure as some apps interact with the tables via insert, update statements.

Many thanks anyway, but I'm still looking.

Warwick
 
They are triggered first because we need to delete records from child tables first, then parent.

I don't see a solution here without using the application level flag.

PluralSight Learning Library
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top