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

Answers were Sorted based on User's Feedback



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

Answer / anil_abbireddy

1. Triggers are Table dependent,But Procedures are Not
2. We can not pass Parameters through Triggers,But in case
of sp we can pass no.of parameters
3. We can not execute triggers explicitly,but ps we can
4. we can not place transaction processing statments in
triggers(commit,collback,save point), but in ps. we can
5. we cannot overload triggers, but we can overload
functions & procedures using packages.

Is This Answer Correct ?    44 Yes 8 No

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

Answer / 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

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

Answer / sohail

1.Procedure is a subrotine which completly utilises the
concept of stack.
2.Procedure can be called any time when required where as
trigger once created we cannot stop the trigger to fire
when not required.
3.triggers are fired implicitly where as procedure are
called explicitly by procedure name when required.
4.the p_code of procedure is stored in oracle SGA and can
be global to others.

Is This Answer Correct ?    14 Yes 11 No

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

Answer / jaya

1) Stored procedures can accept parameters and can return values. Triggers can neither accept parameters nor return values.

2) A Trigger is dependent on a table and the application has no control to not fire a trigger when not needed. On the other hand, a stored procedure can be called as needed.

3) Procedure runs only when one call them manually whereas a trigger runs when there is any activity(insert,update,delete) on table on which the trigger is written.
4) Firing of a stored procedure can be controlled whereas on the other hand trigger will get fired whenever any modification takes place on the table.

Is This Answer Correct ?    4 Yes 1 No

Post New Answer

More SQL PLSQL Interview Questions

why should required for Indexed by table in pl/sql

3 Answers  


Why is sql*loader direct path so fast?

0 Answers  


What is relationship? How many types of relationship are there?

0 Answers  


How you improve the performance of sql*loader? : aql loader

0 Answers  


What are variables in pl sql?

0 Answers  






Do stored procedures prevent sql injection?

0 Answers  


Explain two virtual tables available at the time of database trigger execution.

1 Answers  


What is difference between CHAR and VARCHAR2?What is the maximum SIZE allowed for each type?

6 Answers   Saama Tech,


What will you get by the cursor attribute sql%rowcount?

0 Answers  


What is the difference between cross join and natural join?

0 Answers  


How toimport .dmp file in lower version of oracle from higher version ?

4 Answers   TCS,


What is crud sql?

0 Answers  


Categories