|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
Hi
I wanted to know the major difference between Triggers and Procedure . |
|
#2
|
||||
|
||||
|
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 |
|
#3
|
|||
|
|||
|
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 |
|
#4
|
||||
|
||||
|
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. |
|
#5
|
||||
|
||||
|
Procedures are also usually precompiled (their executaion path is predefined) - allowing for much faster execution than dynamic SQL.
|
![]() |
| Viewing: Dev Articles Community Forums > Databases > General SQL Development > Difference between Triggers and Procedure |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|