What is difference between triggers and stored procedures.
And advantages of SP over triggers ?

Answer Posted / ravi singh

Procedures:
- A procedure is PL/SQL block which is used to process a value and need to execute explicitly.
- Procedure can be call when required and it don't have any dependency on any DML operations on any table.
- Procedure can be called from any area of the code.
- You can pass IN/OUT parameters to the procedure through which you can use the output of the procedures.

Triggers:
- Triggers are PL/SQL block which are based on the events and got executed on the happening of any DML event on the specific table.
- They cannot be called or you cannot stop them from execution.
- You can write commit in the triggers with the help of autonomous transaction only.
- You can refer the values of the table with whom the trigger is linked with the help of :new and :old variables.

Advantages and Disadvantages: They both are mentioned in the above two posted answers.
But one main advantage of triggers over procedures is if you want to perform any action on the DML event of any table you should use triggers as you dont need to make a seperate call for your code.
One main disadvantage of triggers you cannot stop them being executed if you want to do it you have to explicitly disable the trigger.

Is This Answer Correct ?    8 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

what is 'mysqlcheck'? : Sql dba

566


Is inner join same as self join?

573


What are the most important characteristics of pl/sql?

570


What is pl/sql table? Why it is used?

556


Why is stored procedure faster than query?

486






What does 0 mean in sql?

526


how do you know the version of your mysql server? : Sql dba

502


How will you distinguish a global variable with a local variable in pl/sql?

618


How to use sql statements in pl/sql?

578


how to present a past time in hours, minutes and seconds? : Sql dba

551


How to create a menu in sqlplus or pl/sql?

605


how many columns can be used for creating index? : Sql dba

511


What is a subquery in sql?

501


Explain the insert into statements in sql?

561


define sql insert statement ? : Sql dba

546