<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Purpose of creating SQL Server stored procedures at run time</title>
	<atom:link href="http://itknowledgeexchange.techtarget.com/itanswers/purpose-of-creating-stored-procedures-at-run-time/feed/" rel="self" type="application/rss+xml" />
	<link>http://itknowledgeexchange.techtarget.com/itanswers/purpose-of-creating-stored-procedures-at-run-time/</link>
	<description></description>
	<lastBuildDate>Thu, 20 Jun 2013 11:12:44 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
	<item>
		<title>By: kccrosser</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/purpose-of-creating-stored-procedures-at-run-time/#comment-64169</link>
		<dc:creator>kccrosser</dc:creator>
		<pubDate>Wed, 03 Jun 2009 00:34:46 +0000</pubDate>
		<guid isPermaLink="false">#comment-64169</guid>
		<description><![CDATA[I think we are still confused by your question.  Are you asking why/when would you dynamically create a stored procedure at run time, or why would you use dynamic SQL at run time?  The two questions are quite different.

Dynamically created stored procedures are most often used from client-side applications, where you might define a SQL query function (in VisualBasic, for example), which is then dynamically compiled at run time and exists only during the application session.  These are often used by applications that are trying to remain &quot;database neutral&quot; - the code is dynamically built and compiled with the appropriate database engine syntax and other quirks at run time based on the database connection.  Usually the code itself isn&#039;t &quot;dynamic&quot; - it is created as static code and is only dynamic because it is compiled at run time.  I am not sure I see many uses for generating and compiling &quot;dynamic procedures&quot; in native Transact-SQL or native PL/SQL (for Oracle).

Building and executing dynamic SQL is vastly different and heavily used.  Generally, we use dynamic SQL when the native SQL environment doesn&#039;t easily allow a static SQL expression to be used.

For example, you cannot use static SQL expressions to select the table to use for a query at run time.  If I need to run a query against one of several different tables, using a table name as a parameter at run time, the only effective way to do it is to dynamically create and execute the SQL statement.  Tools for migrating, merging, maintenance, etc. tables generally have to use dynamic SQL, as otherwise each reference to a specific table would have to be hard-coded and compiled individually.  (Ok - technically, there are ways to do this without dynamic SQL, but they are much harder and more complex.)

The performance issues with any form of dynamic sql has to do both with the cost of doing the dynamic compilation and with the optimization of the underlying queries.

If you are dynamically compiling a procedure to use once, that is hugely inefficient.  If you are compiling a procedure dynamically, but will then call that procedure 1000 times, the initial compilation overhead may be insignificant.

I may be wrong, but I believe the actual optimization of a dynamically compiled procedure and a dynamic SQL statement are roughly equivalent.  If I was seriously worried about performance, I would be more likely to try to figure out how to minimize any use of dynamic code than to worry about dynamic SQL vs dynamic procedures.]]></description>
		<content:encoded><![CDATA[<p>I think we are still confused by your question.  Are you asking why/when would you dynamically create a stored procedure at run time, or why would you use dynamic SQL at run time?  The two questions are quite different.</p>
<p>Dynamically created stored procedures are most often used from client-side applications, where you might define a SQL query function (in VisualBasic, for example), which is then dynamically compiled at run time and exists only during the application session.  These are often used by applications that are trying to remain &#8220;database neutral&#8221; &#8211; the code is dynamically built and compiled with the appropriate database engine syntax and other quirks at run time based on the database connection.  Usually the code itself isn&#8217;t &#8220;dynamic&#8221; &#8211; it is created as static code and is only dynamic because it is compiled at run time.  I am not sure I see many uses for generating and compiling &#8220;dynamic procedures&#8221; in native Transact-SQL or native PL/SQL (for Oracle).</p>
<p>Building and executing dynamic SQL is vastly different and heavily used.  Generally, we use dynamic SQL when the native SQL environment doesn&#8217;t easily allow a static SQL expression to be used.</p>
<p>For example, you cannot use static SQL expressions to select the table to use for a query at run time.  If I need to run a query against one of several different tables, using a table name as a parameter at run time, the only effective way to do it is to dynamically create and execute the SQL statement.  Tools for migrating, merging, maintenance, etc. tables generally have to use dynamic SQL, as otherwise each reference to a specific table would have to be hard-coded and compiled individually.  (Ok &#8211; technically, there are ways to do this without dynamic SQL, but they are much harder and more complex.)</p>
<p>The performance issues with any form of dynamic sql has to do both with the cost of doing the dynamic compilation and with the optimization of the underlying queries.</p>
<p>If you are dynamically compiling a procedure to use once, that is hugely inefficient.  If you are compiling a procedure dynamically, but will then call that procedure 1000 times, the initial compilation overhead may be insignificant.</p>
<p>I may be wrong, but I believe the actual optimization of a dynamically compiled procedure and a dynamic SQL statement are roughly equivalent.  If I was seriously worried about performance, I would be more likely to try to figure out how to minimize any use of dynamic code than to worry about dynamic SQL vs dynamic procedures.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: skothamasu</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/purpose-of-creating-stored-procedures-at-run-time/#comment-64136</link>
		<dc:creator>skothamasu</dc:creator>
		<pubDate>Mon, 01 Jun 2009 15:20:48 +0000</pubDate>
		<guid isPermaLink="false">#comment-64136</guid>
		<description><![CDATA[Hi,
Thaks for your reply.
I just wanted to have the basic knowledge of the purpose of dynamic stored procedures.
That&#039;s it.]]></description>
		<content:encoded><![CDATA[<p>Hi,<br />
Thaks for your reply.<br />
I just wanted to have the basic knowledge of the purpose of dynamic stored procedures.<br />
That&#8217;s it.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: carlosdl</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/purpose-of-creating-stored-procedures-at-run-time/#comment-63971</link>
		<dc:creator>carlosdl</dc:creator>
		<pubDate>Wed, 27 May 2009 14:54:02 +0000</pubDate>
		<guid isPermaLink="false">#comment-63971</guid>
		<description><![CDATA[I&#039;m afraid we cannot give any alternative without knowing what you want to accomplish (what is &lt;b&gt;your&lt;/b&gt; purpose ?)]]></description>
		<content:encoded><![CDATA[<p>I&#8217;m afraid we cannot give any alternative without knowing what you want to accomplish (what is <b>your</b> purpose ?)</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using memcached
Database Caching 3/10 queries in 0.041 seconds using memcached
Object Caching 295/301 objects using memcached

Served from: itknowledgeexchange.techtarget.com @ 2013-06-20 11:53:11 -->