Exforsys

Online Training

Triggers

This is a discussion on Triggers within the Oracle Database forums, part of the Database category; Why do one go for triggers concept when we have procedures which does the same functionality.Someone provide me idea ...


Go Back   Exforsys > Database > Oracle Database

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 12-20-2006, 03:05 PM
Senior Member
 
Join Date: Apr 2006
Posts: 144
caradoc is on a distinguished road
Triggers

Why do one go for triggers concept when we have procedures which does the same functionality.Someone provide me idea on this.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 12-21-2006, 05:41 AM
Junior Member
 
Join Date: Aug 2006
Posts: 5
gpraveen_mca is on a distinguished road
Triggers are events that are executed whenever an insert or delete or update happens. Basically, triggers are events and the code associated with triggers is executed automatically when the event occurs. These events are purely database events.

Procedures on other hand, should be run explicitily by the user either from database or from user applications.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 12-23-2006, 02:59 PM
Senior Member
 
Join Date: Apr 2006
Posts: 141
Adrian is on a distinguished road
Hi All,
Nice discussion going around. Can you kindly explain the same with an example so that I can get even more clearer view of the concept.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 12-25-2006, 12:13 AM
Junior Member
 
Join Date: Dec 2006
Posts: 3
neelu.payola is on a distinguished road
the main difference is that Trigger activates automatically if and when condition is meet within the database transaction. It is like a rule in the database whenever a transaction is done and condition is meet.

And

Stored Procedure have to be activated or triggered or called by something in order to activate.



A trigger is generally used to enforce business rules in a database, such as a rental property needs to have an associated landlord in a realestate database, although it can be used to enforce data types or structures as well. for instance:

Code:
create or replace trigger unique_pk before insert or update on table
declare
unique : number;
before each row
begin
select count(*) into unique from table where pk = :new.pk;
if (unique > 0) then
raise_error(-20001,"Primary key allready exists");
end if;
end;

A procedure is something used to make one or more (advanced?) sql queries into a nice little function, for instance:

Code:
create procedure add_rental_property(address : varchar2 etc etc)
insert into landlords lastname, firstname etc etc
insert into property address, rent etc etc
insert into tenant_property null, null etc etc
end
then all you have to do is exec add_rental property("6 elm st.","Freddy","Krueger",etc etc); to do all those sql statements
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools

Posting Rules
You may not post new questions
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads

Thread Thread Starter Forum Replies Last Post
ORACLE INTERVIEW QUESTIONS & ANWSERS satishavula Oracle Tutorials 6 10-07-2004 03:27 PM
Viruses and the Mac FAQ David Harley Tech FAQ 0 04-26-2004 05:46 AM
Viruses and the Mac FAQ David Harley Tech FAQ 0 04-11-2004 07:10 AM


All times are GMT -4. The time now is 03:00 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0
Copyright 2004 - 2007 Exforsys Inc. All rights reserved.