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

How to look at the current sql*plus system settings?

606


What is cross join example?

556


1) Synonyms 2) Co-related Subquery 3) Different Jobs in Plsql 4) Explain Plan 5) Wrap 6) Query Optimization Technique 7) Bulk Collect 8) Types of index 9) IF primary key is created then the index created ? 10) Foreign Key 11) Exception Handling 12) Difference Between Delete and Trunc 13) Procedure Overloading 14) Grant Revoke 15) Procedure Argument types. 16) Functions. 17) Joins

1158


What is the purpose of a sql?

532


What do you understand by exception handling in pl/sql?

579






What is the difference between a subquery and a join?

531


What are secondary keys?

563


Which is faster truncate or drop?

564


What is dml statement?

519


What is the difference between numeric and autonumber?

502


Explain the savepoint statement.

604


What is trigger explain it?

551


What does the argument [or replace] do?

583


how tsql statements can be written and submitted to the database engine? : Transact sql

538


what tools available for managing mysql server? : Sql dba

535