<?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: Temporary Tables vs. Table Variables and Their Effect on SQL Server Performance</title>
	<atom:link href="http://www.sql-server-performance.com/2007/temp-tables-vs-variables/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.sql-server-performance.com/2007/temp-tables-vs-variables/</link>
	<description>SQL Server Performance Tuning</description>
	<lastBuildDate>Fri, 17 May 2013 13:31:24 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
	<item>
		<title>By: shiv mohan</title>
		<link>http://www.sql-server-performance.com/2007/temp-tables-vs-variables/#comment-2206</link>
		<dc:creator>shiv mohan</dc:creator>
		<pubDate>Mon, 10 Sep 2012 12:49:11 +0000</pubDate>
		<guid isPermaLink="false">http://www.sql-server-performance.com/?=941#comment-2206</guid>
		<description><![CDATA[-- First Clean Cache
DBCC FREEPROCCACHE
GO
IF EXISTS (SELECT * FROM sys.sysobjects WHERE TYPE = &#039;P&#039; AND NAME = &#039;up_SampleSP&#039;)
      BEGIN
                  DROP PROCEDURE up_SampleSP
      END
GO
-- Create the Stored Procedure
CREATE PROCEDURE up_SampleSP
AS
      SELECT * into #mytemp
      FROM   dept
      select * from #mytemp
GO
-- Check the Query Plan for SQL Batch
-- [ Result -- You will find that there is no ObjectName with the name of up_SampleSP ]
SELECT   cp.objtype AS PlanType,
         OBJECT_NAME(st.objectid,st.dbid) AS ObjectName,
         cp.refcounts AS ReferenceCounts,
         cp.usecounts AS UseCounts,
         st.TEXT AS SQLBatch,
         qp.query_plan AS QueryPlan
FROM     sys.dm_exec_cached_plans AS cp
         CROSS APPLY sys.dm_exec_query_plan(cp.plan_handle) AS qp
         CROSS APPLY sys.dm_exec_sql_text(cp.plan_handle) AS st;
GO
-- Execute Stored Procedure
EXEC up_SampleSP
GO
-- Check the Query Plan for SQL Batch
-- [ Result -- You will find that there is one entry with name ObjectName with name up_SampleSP ]
SELECT   cp.objtype AS PlanType,
         OBJECT_NAME(st.objectid,st.dbid) AS ObjectName,
         cp.refcounts AS ReferenceCounts,
         cp.usecounts AS UseCounts,
         st.TEXT AS SQLBatch,
         qp.query_plan AS QueryPlan
FROM     sys.dm_exec_cached_plans AS cp
         CROSS APPLY sys.dm_exec_query_plan(cp.plan_handle) AS qp
         CROSS APPLY sys.dm_exec_sql_text(cp.plan_handle) AS st;
GO]]></description>
		<content:encoded><![CDATA[<p>&#8211; First Clean Cache<br />
DBCC FREEPROCCACHE<br />
GO<br />
IF EXISTS (SELECT * FROM sys.sysobjects WHERE TYPE = &#8216;P&#8217; AND NAME = &#8216;up_SampleSP&#8217;)<br />
      BEGIN<br />
                  DROP PROCEDURE up_SampleSP<br />
      END<br />
GO<br />
&#8211; Create the Stored Procedure<br />
CREATE PROCEDURE up_SampleSP<br />
AS<br />
      SELECT * into #mytemp<br />
      FROM   dept</p>
<p>      select * from #mytemp<br />
GO<br />
&#8211; Check the Query Plan for SQL Batch<br />
&#8211; [ Result -- You will find that there is no ObjectName with the name of up_SampleSP ]<br />
SELECT   cp.objtype AS PlanType,<br />
         OBJECT_NAME(st.objectid,st.dbid) AS ObjectName,<br />
         cp.refcounts AS ReferenceCounts,<br />
         cp.usecounts AS UseCounts,<br />
         st.TEXT AS SQLBatch,<br />
         qp.query_plan AS QueryPlan<br />
FROM     sys.dm_exec_cached_plans AS cp<br />
         CROSS APPLY sys.dm_exec_query_plan(cp.plan_handle) AS qp<br />
         CROSS APPLY sys.dm_exec_sql_text(cp.plan_handle) AS st;<br />
GO<br />
&#8211; Execute Stored Procedure<br />
EXEC up_SampleSP<br />
GO<br />
&#8211; Check the Query Plan for SQL Batch<br />
&#8211; [ Result -- You will find that there is one entry with name ObjectName with name up_SampleSP ]<br />
SELECT   cp.objtype AS PlanType,<br />
         OBJECT_NAME(st.objectid,st.dbid) AS ObjectName,<br />
         cp.refcounts AS ReferenceCounts,<br />
         cp.usecounts AS UseCounts,<br />
         st.TEXT AS SQLBatch,<br />
         qp.query_plan AS QueryPlan<br />
FROM     sys.dm_exec_cached_plans AS cp<br />
         CROSS APPLY sys.dm_exec_query_plan(cp.plan_handle) AS qp<br />
         CROSS APPLY sys.dm_exec_sql_text(cp.plan_handle) AS st;<br />
GO</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ervin88</title>
		<link>http://www.sql-server-performance.com/2007/temp-tables-vs-variables/#comment-2028</link>
		<dc:creator>Ervin88</dc:creator>
		<pubDate>Sat, 23 Jun 2012 23:09:32 +0000</pubDate>
		<guid isPermaLink="false">http://www.sql-server-performance.com/?=941#comment-2028</guid>
		<description><![CDATA[I have to disagree with you.
Temporary tables survive the end of the queries, but  table variables doesn&#039;t.
Sometimes, you want to store some data in query #1 and you want to access them in query #2. In that cases you can&#039;t use table variables.
About the performance:
In the first case, I inserted 10 000 rows to a simple table. Then, in the second case I inserted also 10 000 rows to the same table, but inserted their ids to a tmp table too. (with the &quot;OUTPUT INSERTED.id INTO #tmpTable&quot; clause in the insert query)
Sadly, the second solution was six times slower.]]></description>
		<content:encoded><![CDATA[<p>I have to disagree with you.</p>
<p>Temporary tables survive the end of the queries, but  table variables doesn&#8217;t.</p>
<p>Sometimes, you want to store some data in query #1 and you want to access them in query #2. In that cases you can&#8217;t use table variables.</p>
<p>About the performance:<br />
In the first case, I inserted 10 000 rows to a simple table. Then, in the second case I inserted also 10 000 rows to the same table, but inserted their ids to a tmp table too. (with the &#8220;OUTPUT INSERTED.id INTO #tmpTable&#8221; clause in the insert query)</p>
<p>Sadly, the second solution was six times slower.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Raghu</title>
		<link>http://www.sql-server-performance.com/2007/temp-tables-vs-variables/#comment-1760</link>
		<dc:creator>Raghu</dc:creator>
		<pubDate>Tue, 20 Mar 2012 07:04:34 +0000</pubDate>
		<guid isPermaLink="false">http://www.sql-server-performance.com/?=941#comment-1760</guid>
		<description><![CDATA[Hi  Dmitry Tsuranoff,
I am trying to find a better solution for my requirement out of Table variables and Temp tables.I tried aboe mentioned T1 and V1 in SQL server 2008. Surprisingly V1 for 100000 recs is taking more than 5mins. Please let know if I miss anything, below is the code that I executed
create procedure V1
     @total int
as
     declare @V table (n int, s varchar(128))
     declare @t1 datetime
     set @t1=getdate()
     insert into @V select n,s from NUM
          where n%100&gt;0 and n&lt;=@total
     declare @res varchar(128)
     select @res=max(s) from NUM
          where n&lt;=@total and
               not exists(select * from @V V
               where V.n=NUM.n)
	 select datediff(ms,@t1,getdate())
GO]]></description>
		<content:encoded><![CDATA[<p>Hi  Dmitry Tsuranoff,</p>
<p>I am trying to find a better solution for my requirement out of Table variables and Temp tables.I tried aboe mentioned T1 and V1 in SQL server 2008. Surprisingly V1 for 100000 recs is taking more than 5mins. Please let know if I miss anything, below is the code that I executed</p>
<p>create procedure V1<br />
     @total int<br />
as<br />
     declare @V table (n int, s varchar(128))<br />
     declare @t1 datetime<br />
     set @t1=getdate()<br />
     insert into @V select n,s from NUM<br />
          where n%100&gt;0 and n&lt;=@total<br />
     declare @res varchar(128)<br />
     select @res=max(s) from NUM<br />
          where n&lt;=@total and<br />
               not exists(select * from @V V<br />
               where V.n=NUM.n) </p>
<p>	 select datediff(ms,@t1,getdate())<br />
GO</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Dynamic page generated in 0.225 seconds. -->
<!-- Cached page generated by WP-Super-Cache on 2013-05-23 08:42:15 -->
