Home » SQL & PL/SQL » SQL & PL/SQL » trigger vs procedure
trigger vs procedure [message #255640] Wed, 01 August 2007 06:47 Go to next message
spsbombay
Messages: 29
Registered: June 2007
Junior Member

Hi,

Whats the major advantage of Trigger over procedure.
As whatever we implement through trigger can also be done by using procedure.

Regards,
Prashant
Re: trigger vs procedure [message #255642 is a reply to message #255640] Wed, 01 August 2007 06:50 Go to previous messageGo to next message
Maaher
Messages: 7062
Registered: December 2001
Senior Member
A procedure has to be invoked explicitly. A trigger is...triggered by an event. My opinion on triggers: use as little triggers as possible and put as little code as possible in a trigger body. I prefer to put procedure calls in a trigger. That way you keep control over the execution order. If you have two trigges on the same event (same table,...) then you can't tell which one will fire first.

MHE
Re: trigger vs procedure [message #255643 is a reply to message #255640] Wed, 01 August 2007 06:51 Go to previous messageGo to next message
Littlefoot
Messages: 20888
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
And more about the issue can be found here.
Re: trigger vs procedure [message #255649 is a reply to message #255640] Wed, 01 August 2007 06:58 Go to previous messageGo to next message
spsbombay
Messages: 29
Registered: June 2007
Junior Member

Thanx for the response.
But my doubt is, whatever i want to execute in trigger body, i can write the same statements just after the trigger invoking statement.And i will have more control on this way. so why should i use trigger.

Regards,
Prashant
Re: trigger vs procedure [message #255652 is a reply to message #255649] Wed, 01 August 2007 07:07 Go to previous messageGo to next message
Maaher
Messages: 7062
Registered: December 2001
Senior Member
That's just the point: you don't have to invoke the code. The trigger will be fired automatically.

MHE
Re: trigger vs procedure [message #255668 is a reply to message #255649] Wed, 01 August 2007 08:01 Go to previous message
JRowbottom
Messages: 5933
Registered: June 2006
Location: Sunny North Yorkshire, ho...
Senior Member
Quote:
But my doubt is, whatever i want to execute in trigger body, i can write the same statements just after the trigger invoking statement.And i will have more control on this way. so why should i use trigger.


This is exactly the point - you CAN write the same code as the trigger will use, but will you ALWAYS remember to.
By putting code into a trigger, you can guarantee that it will always be executed for that operation on that table. You don't have to worry about people forgetting to do it, or people running ad-hoc sql , it will always happen.
And, if the trigger is designed to prevent something from happening, then would you actually want to rely on people chosing to enforce that logic, rather than them having no choice.

[Updated on: Wed, 01 August 2007 08:39] by Moderator

Report message to a moderator

Previous Topic: v$sort_usage
Next Topic: DDL Operation On Remote database
Goto Forum:
  


Current Time: Sat Dec 03 12:15:35 CST 2016

Total time taken to generate the page: 0.10479 seconds