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

name 3 ways to get an accurate count of the number of records in a table? : Sql dba

0 Answers  


Can we rollback delete command?

0 Answers  


What is ttitle and btitle?

0 Answers  


How to return an array from java to pl/sql?

0 Answers  


Explain foreign key in sql?

0 Answers  






Can u create a primary key with out unique index.

8 Answers  


what is a stored procedure? : Sql dba

0 Answers  


How do you rank data in sql?

0 Answers  


What do you understand by pl/sql packages?

0 Answers  


How to execute OS(operating system) command from pl/sql?

3 Answers  


What type of join is sql join?

0 Answers  


I Have A Table Like This. Cityno Cityname Mails 1 Bangalore 8km 2 Hsr Layout 20km 3 Mejistic 30km 4 Jayadeva 55km 5 Itpl 80km 6 Hebbal 115km I Have Data Like This I Want O/p Like This Distance No.ofcity 0-50km 3 51-100km 2 101-150km 4 And So On

6 Answers   DELL, HCL, Oracle,


Categories