﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / SQL Server 2005 / Development  / Main Store procedure to execute several store procedures or Trigger? / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Thu, 23 May 2013 09:13:45 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Main Store procedure to execute several store procedures or Trigger?</title><link>http://www.sqlservercentral.com/Forums/Topic786775-145-1.aspx</link><description>[quote][b]Jeff Moden (9/12/2009)[/b][hr]You might also want to lookup what OUTPUT does for you, as well.[/quote]Using the OUTPUT clause of the data modification statement is much to be preferred in many cases.Both SCOPE_IDENTITY() and @@IDENTITY are unreliable if a parallel plan was used in the statement that affected the IDENTITY column.  I am unsure about whether IDENT_CURRENT is likewise unreliable in these circumstances.All four options (OUTPUT clause, @@IDENTITY, SCOPE_IDENTITY, and IDENT_CURRENT) have their applications, and all are well documented.When using anything except the OUTPUT clause, I am careful to add an explicit MAXDOP(1).See [url=https://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=328811]this confirmed bug[/url] for details.  Both 2005 and 2008 are affected, and there are no plans to fix it before at least R2.Paul</description><pubDate>Sat, 12 Sep 2009 22:23:53 GMT</pubDate><dc:creator>Paul White</dc:creator></item><item><title>RE: Main Store procedure to execute several store procedures or Trigger?</title><link>http://www.sqlservercentral.com/Forums/Topic786775-145-1.aspx</link><description>You might also want to lookup what OUTPUT does for you, as well.</description><pubDate>Sat, 12 Sep 2009 16:51:49 GMT</pubDate><dc:creator>Jeff Moden</dc:creator></item><item><title>RE: Main Store procedure to execute several store procedures or Trigger?</title><link>http://www.sqlservercentral.com/Forums/Topic786775-145-1.aspx</link><description>I don't have a very good answer for you but I can tell you that using @@IDENTITY, especially if triggers come into play, is a form of "Death by SQL".  Use SCOPE_IDENTITY() instead.  See Books Online for why.</description><pubDate>Sat, 12 Sep 2009 16:50:45 GMT</pubDate><dc:creator>Jeff Moden</dc:creator></item><item><title>RE: Main Store procedure to execute several store procedures or Trigger?</title><link>http://www.sqlservercentral.com/Forums/Topic786775-145-1.aspx</link><description>Well, it really depends on how complicated your data is and what kind of work your triggers do.I, personally, have been avoiding triggers in the past 12 years. I like to keep my code and logic plain simple and "procedural"... It might look somewhat crippled, but as a tech-leader I have the luxury of choosing between readability and sophistication level of a solution. As for your question: If you DO have triggers already - go ahead and use them, as otherwise you'll bump into more problems than you might think of.If you do not have any triggers yet, I recommend you split your code into several SPs and call them from one main SP. It is best solution because:1. Code is broken into logoically different pieces in an elegant way2. You might wanna change one SP without changing tons of lines of code.3. All the reasons for using procedural coding apply here... event the name 'procedural' is a good hint[quote]If I use One Main sp to execute all the child sp's, do I need to call ALL the parameters of the child sp's in the main sp? [/quote]Just like any other SP, you may or may not pass all parameters. You may leave NULLs or DEFAULT keyword, if they apply[quote]If I use a trigger to execute a store procedure? How do I configure the parameters[/quote]In order to do that you should learn, first, about what INSERTED and DELETED logical tables are and take your parameters from there, but then again - It's a trigger based solution, even if a trigger fires SP...</description><pubDate>Fri, 11 Sep 2009 23:41:15 GMT</pubDate><dc:creator>dbo.benyos</dc:creator></item><item><title>Main Store procedure to execute several store procedures or Trigger?</title><link>http://www.sqlservercentral.com/Forums/Topic786775-145-1.aspx</link><description>I have a main table Broker which has an identity field as primary key, once inserted, is supposed to insert relevant data on several other tables by accessing the @@Identity. I have created store procedures for all the other tables. Initially I was planning on just creating triggers to insert data in the child tables, now I am not sure if I should use a trigger to execute a store procedure, or a Main Parent SP to execute all the child sp's If I use One Main sp to execute all the child sp's, do I need to call ALL the parameters of the child sp's in the main sp? If I use a trigger to execute a store procedure? How do I configure the parameters.Any help will be much appreciated.Thanks!</description><pubDate>Fri, 11 Sep 2009 18:28:10 GMT</pubDate><dc:creator>Padma-1078840</dc:creator></item></channel></rss>