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
How do you define a foreign key?
Show code of a cursor for loop.
What are the types of index in sql?
Is vs as in pl sql?
Is grant a ddl statement?
What is percent sign in sql?
What is a clob in sql?
Table A Table B 1 1 2 1 3 1. Union & union all --> A Union B , A Union all B 2. Minus , Intersect --> A minus B , B Minus A , A Intersect B 3. Joins A join B , A Left Join B A Right Join B , A full Join B 4. %Type - Uses & Benifit 5. Truncate & Delete 6. Pragma Autonomus Transaction 7. how to Perform DDL from function or procedure 8. Can we have DML inside Function 9. Rank & Dense Rank diffrence 10. Water Mark in Oracle 11. Index , Can we have index in all column of table if no then why ?
what is heap table? : Sql dba
How to pronounce postgresql?
what does the t-sql command ident_incr does? : Transact sql
Can there be 2 primary keys in a table?
What is prepared statement in sql?
Mention what problem one might face while writing log information to a data-base table in pl/sql?
Why do we use procedures?