can I trust Triggers?
-
Hi, I am currently using stored procedures to do an action after my INSERT, UPDATE or DELETE. I just wanted to ask for your advise.. do you recommend to continue using the stored procedures or start using triggers? my simple example is an event-log table... I insert a row in this table if a row was inserted in employees table. Thanks, Jassim
Technology News @ www.JassimRahma.com
-
Hi, I am currently using stored procedures to do an action after my INSERT, UPDATE or DELETE. I just wanted to ask for your advise.. do you recommend to continue using the stored procedures or start using triggers? my simple example is an event-log table... I insert a row in this table if a row was inserted in employees table. Thanks, Jassim
Technology News @ www.JassimRahma.com
For logging purpose, Trigger is fine. Personally I prefer Stored procedure because you can't control the Trigger. And Trigger Disadvantages[^]
thatraja
Code converters | Education Needed No thanks, I am all stocked up. - Luc Pattyn When you're wrestling a gorilla, you don't stop when you're tired, you stop when the gorilla is - Henry Minute
-
Hi, I am currently using stored procedures to do an action after my INSERT, UPDATE or DELETE. I just wanted to ask for your advise.. do you recommend to continue using the stored procedures or start using triggers? my simple example is an event-log table... I insert a row in this table if a row was inserted in employees table. Thanks, Jassim
Technology News @ www.JassimRahma.com
Jassim Rahma wrote:
my simple example is an event-log table... I insert a row in this table if a row was inserted in employees table.
Can be done both ways. Triggers *could* be harder to debug though. I cannot recommend anything, as that would depend on the requirements of the audit-trail. How does your "event log table" look, and what are you planning on doing with it?
Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]
-
For logging purpose, Trigger is fine. Personally I prefer Stored procedure because you can't control the Trigger. And Trigger Disadvantages[^]
thatraja
Code converters | Education Needed No thanks, I am all stocked up. - Luc Pattyn When you're wrestling a gorilla, you don't stop when you're tired, you stop when the gorilla is - Henry Minute
Your link shows very important information. And from that information, I conclude that it may be a bad decision to use them for logging purposes: in a transaction rollback, also the trigger actions will be rolled back. I.e. when you log by inserting into a table, that will be rolled back, too!
-
Hi, I am currently using stored procedures to do an action after my INSERT, UPDATE or DELETE. I just wanted to ask for your advise.. do you recommend to continue using the stored procedures or start using triggers? my simple example is an event-log table... I insert a row in this table if a row was inserted in employees table. Thanks, Jassim
Technology News @ www.JassimRahma.com
Jassim Rahma wrote:
or start using triggers?
As with anything it depends on the usage.
Jassim Rahma wrote:
my simple example is an event-log table...
Might note that in my experience doing this is often driven by the need for audit logging and it is seldom sufficient as it ignores user, reason and fails to allow deletions to be handled well.
-
Your link shows very important information. And from that information, I conclude that it may be a bad decision to use them for logging purposes: in a transaction rollback, also the trigger actions will be rolled back. I.e. when you log by inserting into a table, that will be rolled back, too!
Sorry for the delay. For beginners(yes he is), Triggers not suggestable. We can't control that. As Eddy said, we can't dubug too. Personally I use Stored procedure instead of trigger. But I rarely use triggers for tasks such as audit trail(During Login/Logout).
thatraja
Code converters | Education Needed No thanks, I am all stocked up. - Luc Pattyn When you're wrestling a gorilla, you don't stop when you're tired, you stop when the gorilla is - Henry Minute
-
Jassim Rahma wrote:
or start using triggers?
As with anything it depends on the usage.
Jassim Rahma wrote:
my simple example is an event-log table...
Might note that in my experience doing this is often driven by the need for audit logging and it is seldom sufficient as it ignores user, reason and fails to allow deletions to be handled well.
so in this case you pefer to do it through SPs?
Technology News @ www.JassimRahma.com