SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Stored Procedure v Trigger
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

sonjan
Starting Member

Australia
21 Posts

Posted - 07/26/2012 :  00:57:20  Show Profile  Reply with Quote
Hi

Haven't created either of above and upon researching stored procedures and triggers, not sure which is best practice to use.

Aim: replacement cost in assetfinbook table is changed, then push that value to replacement cost in asset table IF asset resides in specified site id and status.

Wise advice is very much appreciated.
Thanks
Sonja

lionofdezert
Aged Yak Warrior

Pakistan
864 Posts

Posted - 07/26/2012 :  01:35:28  Show Profile  Visit lionofdezert's Homepage  Send lionofdezert a Yahoo! Message  Reply with Quote
Trigger will be fired automatically on events list INSERT, UPDATE or DELETE, while for stored procedure you have to execute it. So if you need to take action on each record (INSERT, UPDATE or DELETE) then go for trigger, and if you need to update your data in batch later on, then go for stored procedure.

--------------------------
http://connectsql.blogspot.com/
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
47189 Posts

Posted - 07/26/2012 :  10:04:28  Show Profile  Reply with Quote
Trigger can be actually consider as a special kind of procedure which will get executed based on an event (DDL/DML/LOGON)

If your DML process is streamlined (ie INSERT/UPDATE/DELETE taking place only through procedure) then you can enclose the logic in procedure itself otherwise if you've no control over how DML operations happens then go for the trigger approach

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

LoztInSpace
Aged Yak Warrior

876 Posts

Posted - 07/26/2012 :  23:41:06  Show Profile  Reply with Quote
A word of warning on triggers - they have the ability to make systems very confusing with strange events and updates happening for no apparent reason (if you're not aware of them). You can also inadvertently gum up the works quite nicely by doing things all the time that maybe should happen selectively.
To me that sounds like a business rule best done in a SP or the business layer.
If you use triggers at all, I'd strongly recommend them for system level type stuff (logging row update before & after etc) and little, if anything, else.
Go to Top of Page

sonjan
Starting Member

Australia
21 Posts

Posted - 07/27/2012 :  00:30:04  Show Profile  Reply with Quote
Thank you all for your advice. I am skeptical of triggers will do some more research.

Regards
Sonja
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000