SunQuest
 
           General SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesGeneral SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old February 23rd, 2004, 12:42 AM
Chinnu Chinnu is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 1 Chinnu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question Difference between Triggers and Procedure

Hi
I wanted to know the major difference between Triggers and Procedure .

Reply With Quote
  #2  
Old February 24th, 2004, 06:51 AM
Spongy's Avatar
Spongy Spongy is offline
Alternately High
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Location: Hilversum, Netherlands
Posts: 223 Spongy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 56 m 41 sec
Reputation Power: 5
Send a message via MSN to Spongy
Then you are at the wrong catagorie.
Try and search Google, I bet there are lot's of articles about this.

Cheers
__________________
Work to live, don't live to work

Reply With Quote
  #3  
Old February 25th, 2004, 07:09 PM
Brick1235 Brick1235 is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 31 Brick1235 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
uhmmm If I am not mistaken 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.

Correct me if I am wrong.

NHK

Reply With Quote
  #4  
Old February 26th, 2004, 12:43 AM
merliin's Avatar
merliin merliin is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Location: Melbourne, Australia
Posts: 30 merliin User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Correct. 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.

You didn't mention functions, so I thought I would. Functions are much the same as procedures, but returns a value. Example:
Code:
create function rent_due("address") : number
declare
  owed : money;
begin
  select sum(paid_rent) from property_rent where address = :address into owed;
  return owed;
end;


then the end user only needs to do select rent_due("6 elm st.") from dual;

Hope this helps.

Reply With Quote
  #5  
Old February 26th, 2004, 04:08 AM
stumpy's Avatar
stumpy stumpy is offline
May contain nuts.
Dev Articles Regular (2000 - 2499 posts)
 
Join Date: Aug 2002
Location: Sydney, AU
Posts: 2,058 stumpy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 6 m 11 sec
Reputation Power: 8
Send a message via ICQ to stumpy Send a message via MSN to stumpy
Procedures are also usually precompiled (their executaion path is predefined) - allowing for much faster execution than dynamic SQL.
__________________
DevArticles Moderator
BlueSix - Web Development and Consulting

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesGeneral SQL Development > Difference between Triggers and Procedure


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway