<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: SQL SERVER &#8211; Difference TempTable and Table Variable &#8211; TempTable in Memory a Myth</title>
	<atom:link href="http://blog.sqlauthority.com/2009/12/15/sql-server-difference-temptable-and-table-variable-temptable-in-memory-a-myth/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.sqlauthority.com/2009/12/15/sql-server-difference-temptable-and-table-variable-temptable-in-memory-a-myth/</link>
	<description>Personal Notes of Pinal Dave</description>
	<lastBuildDate>Mon, 13 Feb 2012 15:11:24 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>By: SQL SERVER &#8211; Debate &#8211; Table Variables vs Temporary Tables &#8211; Quiz &#8211; Puzzle &#8211; 13 of 31 &#171; SQL Server Journey with SQL Authority</title>
		<link>http://blog.sqlauthority.com/2009/12/15/sql-server-difference-temptable-and-table-variable-temptable-in-memory-a-myth/#comment-236860</link>
		<dc:creator><![CDATA[SQL SERVER &#8211; Debate &#8211; Table Variables vs Temporary Tables &#8211; Quiz &#8211; Puzzle &#8211; 13 of 31 &#171; SQL Server Journey with SQL Authority]]></dc:creator>
		<pubDate>Sat, 14 Jan 2012 01:31:59 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=7544#comment-236860</guid>
		<description><![CDATA[[...] ISBN: 1466405643 Page#75-76  Difference Temp Table and Table Variable – Effect of Transaction Difference TempTable and Table Variable – TempTable in Memory a Myth  ObjectID in Negative – Local TempTable has Negative [...]]]></description>
		<content:encoded><![CDATA[<p>[...] ISBN: 1466405643 Page#75-76  Difference Temp Table and Table Variable – Effect of Transaction Difference TempTable and Table Variable – TempTable in Memory a Myth  ObjectID in Negative – Local TempTable has Negative [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chandra</title>
		<link>http://blog.sqlauthority.com/2009/12/15/sql-server-difference-temptable-and-table-variable-temptable-in-memory-a-myth/#comment-236211</link>
		<dc:creator><![CDATA[Chandra]]></dc:creator>
		<pubDate>Thu, 12 Jan 2012 20:51:26 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=7544#comment-236211</guid>
		<description><![CDATA[Hello, In terms of performance, is it better to create the temp table and use it or is it better to create the temp table on the fly?

Is this better to do as below:
create table #tv_target (c11 int, c22 char(100))
go

INSERT INTO #tv_target (c11, c22)
SELECT c1, c2  FROM tv_source

or is it better to do as below:
SELECT c1, c2  into #tv_target 
FROM tv_source]]></description>
		<content:encoded><![CDATA[<p>Hello, In terms of performance, is it better to create the temp table and use it or is it better to create the temp table on the fly?</p>
<p>Is this better to do as below:<br />
create table #tv_target (c11 int, c22 char(100))<br />
go</p>
<p>INSERT INTO #tv_target (c11, c22)<br />
SELECT c1, c2  FROM tv_source</p>
<p>or is it better to do as below:<br />
SELECT c1, c2  into #tv_target<br />
FROM tv_source</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: said</title>
		<link>http://blog.sqlauthority.com/2009/12/15/sql-server-difference-temptable-and-table-variable-temptable-in-memory-a-myth/#comment-188845</link>
		<dc:creator><![CDATA[said]]></dc:creator>
		<pubDate>Sat, 05 Nov 2011 11:33:11 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=7544#comment-188845</guid>
		<description><![CDATA[Hello,


please,How can I programaticaly get the structure of Table variable ?.

i can get the name from sys.type but not the metada.

need help.]]></description>
		<content:encoded><![CDATA[<p>Hello,</p>
<p>please,How can I programaticaly get the structure of Table variable ?.</p>
<p>i can get the name from sys.type but not the metada.</p>
<p>need help.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jitesh</title>
		<link>http://blog.sqlauthority.com/2009/12/15/sql-server-difference-temptable-and-table-variable-temptable-in-memory-a-myth/#comment-142420</link>
		<dc:creator><![CDATA[jitesh]]></dc:creator>
		<pubDate>Mon, 20 Jun 2011 09:41:24 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=7544#comment-142420</guid>
		<description><![CDATA[First, the table variable is NOT necessarily memory resident. Under memory pressure, the pages belonging to a table variable can be pushed out to tempdb. Here is one example shows space taken by table variable in tempdb

        use tempdb

        go

         

        drop table #tv_source

        go

         

        create table #tv_source(c1 int, c2 char(8000))

        go

         

        declare @i int

        select @i = 0

        while (@i  100 and name like &#039;c%&#039;

This will return two rows containing columns c111 and c222. Now this means that if you were encountering DDL contention, you cannot address it by changing a #table to table variable.

·         Third, transactional and locking semantics. Table variables don’t participate in transactions or locking. Here is one example


-- create a source table

create table tv_source(c1 int, c2 char(100))

go

 

declare @i int

select @i = 0

while (@i &lt; 100)

begin

       insert into tv_source values (@i, replicate (&#039;a&#039;, 100))

       select @i = @i + 1

       end

-- using #table

create table #tv_target (c11 int, c22 char(100))

go

 

BEGIN TRAN

 

    INSERT INTO #tv_target (c11, c22)

            SELECT c1, c2

            FROM  tv_source

 

 

-- using table variable

 

DECLARE @tv_target TABLE (c11 int, c22 char(100))

 

BEGIN TRAN

       INSERT INTO @tv_target (c11, c22)

        SELECT c1, c2

    FROM  tv_source

 

 

-- Now if I look at the locks, you will see that only

-- #table takes locks. Here is the query that used

-- to check the locks   

select 

    t1.request_session_id as spid, 

    t1.resource_type as type,  

    t1.resource_database_id as dbid, 

    (case resource_type

      WHEN &#039;OBJECT&#039; then object_name(t1.resource_associated_entity_id)

      WHEN &#039;DATABASE&#039; then &#039; &#039;

      ELSE (select object_name(object_id) 

            from sys.partitions 

            where hobt_id=resource_associated_entity_id)

    END) as objname, 

    t1.resource_description as description,  

    t1.request_mode as mode, 

    t1.request_status as status,

       t2.blocking_session_id

from sys.dm_tran_locks as t1 left outer join sys.dm_os_waiting_tasks as t2

ON t1.lock_owner_address = t2.resource_address

 

Another interesting aspect is that if I rollback the transaction involving the table variable earlier, the data in the table variable is not rolled back.

Rollback

-- this query will return 100 for table variable but 0 for #table.

SELECT COUNT(*) FROM @tv_target

·         Fourth, the operations done on table variable are not logged. Here is the example I tried

-- create a table variable, insert bunch of rows and update

DECLARE @tv_target TABLE (c11 int, c22 char(100))

 

INSERT INTO @tv_target (c11, c22)

    SELECT c1, c2

    FROM  tv_source

 

 

-- update all the rows

update @tv_target set c22 = replicate (&#039;b&#039;, 100)

 

 

-- look at the top 10 log records. I get no records for this case

select top 10 operation,context, [log record fixed length], [log record length], AllocUnitId, AllocUnitName

from fn_dblog(null, null)

where AllocUnitName like &#039;%tv_target%&#039;

order by [Log Record Length] Desc

 

-- create a local temptable

drop table #tv_target

go

 

create table #tv_target (c11 int, c22 char(100))

go

 

INSERT INTO #tv_target (c11, c22)

    SELECT c1, c2

    FROM  tv_source

 

-- update all the rows

update #tv_target set c22 = replicate (&#039;b&#039;, 100)

 

 

-- look at the log records. Here I get 100 log records for update

select  operation,context, [log record fixed length], [log record length], AllocUnitName

from fn_dblog(null, null)

where AllocUnitName like &#039;%tv_target%&#039;

order by [Log Record Length] Desc

 

·         Fifth, no DDL is allowed on table variables. So if you have a large rowset which needs to be queried often, you may want to use #table when possible so that you can create appropriate indexes. You can get around this by creating unique constraints when declaring table variable.

 

·         Finally, no statistics is maintained on table variable which means that any changes in data impacting table variable will not cause recompilation of queries accessing table variable.]]></description>
		<content:encoded><![CDATA[<p>First, the table variable is NOT necessarily memory resident. Under memory pressure, the pages belonging to a table variable can be pushed out to tempdb. Here is one example shows space taken by table variable in tempdb</p>
<p>        use tempdb</p>
<p>        go</p>
<p>        drop table #tv_source</p>
<p>        go</p>
<p>        create table #tv_source(c1 int, c2 char(8000))</p>
<p>        go</p>
<p>        declare @i int</p>
<p>        select @i = 0</p>
<p>        while (@i  100 and name like &#8216;c%&#8217;</p>
<p>This will return two rows containing columns c111 and c222. Now this means that if you were encountering DDL contention, you cannot address it by changing a #table to table variable.</p>
<p>·         Third, transactional and locking semantics. Table variables don’t participate in transactions or locking. Here is one example</p>
<p>&#8211; create a source table</p>
<p>create table tv_source(c1 int, c2 char(100))</p>
<p>go</p>
<p>declare @i int</p>
<p>select @i = 0</p>
<p>while (@i &lt; 100)</p>
<p>begin</p>
<p>       insert into tv_source values (@i, replicate (&#039;a&#039;, 100))</p>
<p>       select @i = @i + 1</p>
<p>       end</p>
<p>&#8211; using #table</p>
<p>create table #tv_target (c11 int, c22 char(100))</p>
<p>go</p>
<p>BEGIN TRAN</p>
<p>    INSERT INTO #tv_target (c11, c22)</p>
<p>            SELECT c1, c2</p>
<p>            FROM  tv_source</p>
<p>&#8211; using table variable</p>
<p>DECLARE @tv_target TABLE (c11 int, c22 char(100))</p>
<p>BEGIN TRAN</p>
<p>       INSERT INTO @tv_target (c11, c22)</p>
<p>        SELECT c1, c2</p>
<p>    FROM  tv_source</p>
<p>&#8211; Now if I look at the locks, you will see that only</p>
<p>&#8211; #table takes locks. Here is the query that used</p>
<p>&#8211; to check the locks   </p>
<p>select </p>
<p>    t1.request_session_id as spid, </p>
<p>    t1.resource_type as type,  </p>
<p>    t1.resource_database_id as dbid, </p>
<p>    (case resource_type</p>
<p>      WHEN &#039;OBJECT&#039; then object_name(t1.resource_associated_entity_id)</p>
<p>      WHEN &#039;DATABASE&#039; then &#039; &#039;</p>
<p>      ELSE (select object_name(object_id) </p>
<p>            from sys.partitions </p>
<p>            where hobt_id=resource_associated_entity_id)</p>
<p>    END) as objname, </p>
<p>    t1.resource_description as description,  </p>
<p>    t1.request_mode as mode, </p>
<p>    t1.request_status as status,</p>
<p>       t2.blocking_session_id</p>
<p>from sys.dm_tran_locks as t1 left outer join sys.dm_os_waiting_tasks as t2</p>
<p>ON t1.lock_owner_address = t2.resource_address</p>
<p>Another interesting aspect is that if I rollback the transaction involving the table variable earlier, the data in the table variable is not rolled back.</p>
<p>Rollback</p>
<p>&#8211; this query will return 100 for table variable but 0 for #table.</p>
<p>SELECT COUNT(*) FROM @tv_target</p>
<p>·         Fourth, the operations done on table variable are not logged. Here is the example I tried</p>
<p>&#8211; create a table variable, insert bunch of rows and update</p>
<p>DECLARE @tv_target TABLE (c11 int, c22 char(100))</p>
<p>INSERT INTO @tv_target (c11, c22)</p>
<p>    SELECT c1, c2</p>
<p>    FROM  tv_source</p>
<p>&#8211; update all the rows</p>
<p>update @tv_target set c22 = replicate (&#039;b&#039;, 100)</p>
<p>&#8211; look at the top 10 log records. I get no records for this case</p>
<p>select top 10 operation,context, [log record fixed length], [log record length], AllocUnitId, AllocUnitName</p>
<p>from fn_dblog(null, null)</p>
<p>where AllocUnitName like &#039;%tv_target%&#039;</p>
<p>order by [Log Record Length] Desc</p>
<p>&#8211; create a local temptable</p>
<p>drop table #tv_target</p>
<p>go</p>
<p>create table #tv_target (c11 int, c22 char(100))</p>
<p>go</p>
<p>INSERT INTO #tv_target (c11, c22)</p>
<p>    SELECT c1, c2</p>
<p>    FROM  tv_source</p>
<p>&#8211; update all the rows</p>
<p>update #tv_target set c22 = replicate (&#039;b&#039;, 100)</p>
<p>&#8211; look at the log records. Here I get 100 log records for update</p>
<p>select  operation,context, [log record fixed length], [log record length], AllocUnitName</p>
<p>from fn_dblog(null, null)</p>
<p>where AllocUnitName like &#039;%tv_target%&#039;</p>
<p>order by [Log Record Length] Desc</p>
<p>·         Fifth, no DDL is allowed on table variables. So if you have a large rowset which needs to be queried often, you may want to use #table when possible so that you can create appropriate indexes. You can get around this by creating unique constraints when declaring table variable.</p>
<p>·         Finally, no statistics is maintained on table variable which means that any changes in data impacting table variable will not cause recompilation of queries accessing table variable.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michael1047</title>
		<link>http://blog.sqlauthority.com/2009/12/15/sql-server-difference-temptable-and-table-variable-temptable-in-memory-a-myth/#comment-141416</link>
		<dc:creator><![CDATA[Michael1047]]></dc:creator>
		<pubDate>Thu, 16 Jun 2011 15:33:36 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=7544#comment-141416</guid>
		<description><![CDATA[If memory serves me correctly, it&#039;s not about in-memory or not; it&#039;s all about scope of the connection.  #TableName will get you in trouble with web services that use one connection.  However, if you use table variables, the temp table is contained within the scope of the stored procedure.]]></description>
		<content:encoded><![CDATA[<p>If memory serves me correctly, it&#8217;s not about in-memory or not; it&#8217;s all about scope of the connection.  #TableName will get you in trouble with web services that use one connection.  However, if you use table variables, the temp table is contained within the scope of the stored procedure.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Saravanakumar</title>
		<link>http://blog.sqlauthority.com/2009/12/15/sql-server-difference-temptable-and-table-variable-temptable-in-memory-a-myth/#comment-123588</link>
		<dc:creator><![CDATA[Saravanakumar]]></dc:creator>
		<pubDate>Thu, 17 Mar 2011 05:12:46 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=7544#comment-123588</guid>
		<description><![CDATA[Pinal dave, I have used Global temp table and temp table.
Temp table has dropped once the query get closed,
Global temp table has dropped once the connection where it created get closed but in your definition you have mentioned that the global temp table definition will remain permanently, how ? kindly give me explaination..]]></description>
		<content:encoded><![CDATA[<p>Pinal dave, I have used Global temp table and temp table.<br />
Temp table has dropped once the query get closed,<br />
Global temp table has dropped once the connection where it created get closed but in your definition you have mentioned that the global temp table definition will remain permanently, how ? kindly give me explaination..</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: pramod kumar sharma</title>
		<link>http://blog.sqlauthority.com/2009/12/15/sql-server-difference-temptable-and-table-variable-temptable-in-memory-a-myth/#comment-122497</link>
		<dc:creator><![CDATA[pramod kumar sharma]]></dc:creator>
		<pubDate>Wed, 09 Mar 2011 05:31:53 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=7544#comment-122497</guid>
		<description><![CDATA[Hello,
         In my case when I use table variable my query time counts 7 sec and for temp table it is near about 30 sec.
my main table rows are 3 million. After reading all these comments i am confuesd what should i use ?

according to this blog table variable consumes double size then temp table.


Plz make me happy with some usefull advice.

Thanks &amp; Regards
Pramod sharma]]></description>
		<content:encoded><![CDATA[<p>Hello,<br />
         In my case when I use table variable my query time counts 7 sec and for temp table it is near about 30 sec.<br />
my main table rows are 3 million. After reading all these comments i am confuesd what should i use ?</p>
<p>according to this blog table variable consumes double size then temp table.</p>
<p>Plz make me happy with some usefull advice.</p>
<p>Thanks &amp; Regards<br />
Pramod sharma</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Darren Harvey</title>
		<link>http://blog.sqlauthority.com/2009/12/15/sql-server-difference-temptable-and-table-variable-temptable-in-memory-a-myth/#comment-90303</link>
		<dc:creator><![CDATA[Darren Harvey]]></dc:creator>
		<pubDate>Thu, 30 Sep 2010 10:50:45 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=7544#comment-90303</guid>
		<description><![CDATA[My ten pence.

I have a rule of thumb that you should use what ever tool is best for the job.

In this case temp tables or table variables.

When having to run a &#039;while&#039; loop or having to rerun the query many times, OR if I need to create a rank in a set of data the Table variable is best as you can program your SQL to run like you would run a data set in code, you have no need to have to keep dropping the table (which is always annoying), and you can use a quick ID identity field  in the table variable create script that can give you a handy rank, rownumber or sequence number.

Use Temp tables for all else and don&#039;t forget the temp table has the global option which is very useful too when having two connections open and running multiple tests at the same time.

When putting together the design in the first place you may find that creating a non temporary static table is always the best option, maybe developers get too hung up on leaving the workings out in the database, when in fact it makes debugging and picking up other peoples development far easier and you can index in the normal fashion improving performance.

Regards

Darren Harvey 
BI Dude MCTS, MCITP, MCDBA]]></description>
		<content:encoded><![CDATA[<p>My ten pence.</p>
<p>I have a rule of thumb that you should use what ever tool is best for the job.</p>
<p>In this case temp tables or table variables.</p>
<p>When having to run a &#8216;while&#8217; loop or having to rerun the query many times, OR if I need to create a rank in a set of data the Table variable is best as you can program your SQL to run like you would run a data set in code, you have no need to have to keep dropping the table (which is always annoying), and you can use a quick ID identity field  in the table variable create script that can give you a handy rank, rownumber or sequence number.</p>
<p>Use Temp tables for all else and don&#8217;t forget the temp table has the global option which is very useful too when having two connections open and running multiple tests at the same time.</p>
<p>When putting together the design in the first place you may find that creating a non temporary static table is always the best option, maybe developers get too hung up on leaving the workings out in the database, when in fact it makes debugging and picking up other peoples development far easier and you can index in the normal fashion improving performance.</p>
<p>Regards</p>
<p>Darren Harvey<br />
BI Dude MCTS, MCITP, MCDBA</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Manoj Pandey</title>
		<link>http://blog.sqlauthority.com/2009/12/15/sql-server-difference-temptable-and-table-variable-temptable-in-memory-a-myth/#comment-80794</link>
		<dc:creator><![CDATA[Manoj Pandey]]></dc:creator>
		<pubDate>Mon, 19 Jul 2010 13:38:44 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=7544#comment-80794</guid>
		<description><![CDATA[The following stmt gives me the temp tables I created:
SELECT TABLE_NAME 
FROM tempdb.INFORMATION_SCHEMA.TABLES
WHERE TABLE_NAME LIKE &#039;%#%&#039;;

But it does not show me the table variables created in tempdb.

How can I get the list of table variables created in tempdb?]]></description>
		<content:encoded><![CDATA[<p>The following stmt gives me the temp tables I created:<br />
SELECT TABLE_NAME<br />
FROM tempdb.INFORMATION_SCHEMA.TABLES<br />
WHERE TABLE_NAME LIKE &#8216;%#%&#8217;;</p>
<p>But it does not show me the table variables created in tempdb.</p>
<p>How can I get the list of table variables created in tempdb?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nitin</title>
		<link>http://blog.sqlauthority.com/2009/12/15/sql-server-difference-temptable-and-table-variable-temptable-in-memory-a-myth/#comment-60421</link>
		<dc:creator><![CDATA[Nitin]]></dc:creator>
		<pubDate>Sat, 30 Jan 2010 10:14:54 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=7544#comment-60421</guid>
		<description><![CDATA[I want to do replication of two tables having two diff names and (same structure but diff records )
in single table at subscriber side.

Is it possible in SQL server 2008 or 2005.

Please give me solution.]]></description>
		<content:encoded><![CDATA[<p>I want to do replication of two tables having two diff names and (same structure but diff records )<br />
in single table at subscriber side.</p>
<p>Is it possible in SQL server 2008 or 2005.</p>
<p>Please give me solution.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nitin</title>
		<link>http://blog.sqlauthority.com/2009/12/15/sql-server-difference-temptable-and-table-variable-temptable-in-memory-a-myth/#comment-60379</link>
		<dc:creator><![CDATA[Nitin]]></dc:creator>
		<pubDate>Fri, 29 Jan 2010 12:44:47 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=7544#comment-60379</guid>
		<description><![CDATA[Thanks a lot...
it was  my mistake...]]></description>
		<content:encoded><![CDATA[<p>Thanks a lot&#8230;<br />
it was  my mistake&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: IAS</title>
		<link>http://blog.sqlauthority.com/2009/12/15/sql-server-difference-temptable-and-table-variable-temptable-in-memory-a-myth/#comment-60322</link>
		<dc:creator><![CDATA[IAS]]></dc:creator>
		<pubDate>Thu, 28 Jan 2010 09:54:10 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=7544#comment-60322</guid>
		<description><![CDATA[@Nitin :

I think u r missing table name in the last..
It shud be:

SELECT TOP 3000 ROW_NUMBER() OVER (ORDER BY name) from TEST]]></description>
		<content:encoded><![CDATA[<p>@Nitin :</p>
<p>I think u r missing table name in the last..<br />
It shud be:</p>
<p>SELECT TOP 3000 ROW_NUMBER() OVER (ORDER BY name) from TEST</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nitin</title>
		<link>http://blog.sqlauthority.com/2009/12/15/sql-server-difference-temptable-and-table-variable-temptable-in-memory-a-myth/#comment-60095</link>
		<dc:creator><![CDATA[Nitin]]></dc:creator>
		<pubDate>Fri, 22 Jan 2010 12:48:15 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=7544#comment-60095</guid>
		<description><![CDATA[Please see this query :- 

SELECT TOP 3000 ROW_NUMBER() OVER(ORDER BY a.name)

gives error like 

&#039;ROW_NUMBER&#039; is not a recognized function name.
when i run ito SQL 2005


Please can u tell me function for gettin rowno in
MS-SQL-2005 or 2008]]></description>
		<content:encoded><![CDATA[<p>Please see this query :- </p>
<p>SELECT TOP 3000 ROW_NUMBER() OVER(ORDER BY a.name)</p>
<p>gives error like </p>
<p>&#8216;ROW_NUMBER&#8217; is not a recognized function name.<br />
when i run ito SQL 2005</p>
<p>Please can u tell me function for gettin rowno in<br />
MS-SQL-2005 or 2008</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Pinal Dave</title>
		<link>http://blog.sqlauthority.com/2009/12/15/sql-server-difference-temptable-and-table-variable-temptable-in-memory-a-myth/#comment-59797</link>
		<dc:creator><![CDATA[Pinal Dave]]></dc:creator>
		<pubDate>Fri, 15 Jan 2010 13:53:02 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=7544#comment-59797</guid>
		<description><![CDATA[Hello Jakey,

Table variables performs good only for small resordset. Because there data statistics is not used while creating the execution plan and because of that sometimes fully optimized plan are not created.
Table variable should be used where they are joined with small tables only.

There are many more details which are associated with table variables but this is just one line answer here.

Regards,
Pinal Dave]]></description>
		<content:encoded><![CDATA[<p>Hello Jakey,</p>
<p>Table variables performs good only for small resordset. Because there data statistics is not used while creating the execution plan and because of that sometimes fully optimized plan are not created.<br />
Table variable should be used where they are joined with small tables only.</p>
<p>There are many more details which are associated with table variables but this is just one line answer here.</p>
<p>Regards,<br />
Pinal Dave</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jakey</title>
		<link>http://blog.sqlauthority.com/2009/12/15/sql-server-difference-temptable-and-table-variable-temptable-in-memory-a-myth/#comment-59718</link>
		<dc:creator><![CDATA[jakey]]></dc:creator>
		<pubDate>Thu, 14 Jan 2010 04:59:31 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=7544#comment-59718</guid>
		<description><![CDATA[On our test/development database server (2 sql server instances) with 4GB memory had a proc using table variabes and was running over 5 minutes.  Changed to temp tables and is now running under 30 seconds.  In production (single instance with 4GB) ran fine with table variables - around 30 seconds.  Assuming memory constraints contributed to poor performance on test/development server, rather than stats.]]></description>
		<content:encoded><![CDATA[<p>On our test/development database server (2 sql server instances) with 4GB memory had a proc using table variabes and was running over 5 minutes.  Changed to temp tables and is now running under 30 seconds.  In production (single instance with 4GB) ran fine with table variables &#8211; around 30 seconds.  Assuming memory constraints contributed to poor performance on test/development server, rather than stats.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: SQL SERVER – Difference Temp Table and Table Variable – Effect of Transaction Journey to SQL Authority with Pinal Dave</title>
		<link>http://blog.sqlauthority.com/2009/12/15/sql-server-difference-temptable-and-table-variable-temptable-in-memory-a-myth/#comment-59033</link>
		<dc:creator><![CDATA[SQL SERVER – Difference Temp Table and Table Variable – Effect of Transaction Journey to SQL Authority with Pinal Dave]]></dc:creator>
		<pubDate>Mon, 28 Dec 2009 01:31:33 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=7544#comment-59033</guid>
		<description><![CDATA[[...] December 28, 2009 by pinaldave    Few days ago I wrote an article on the myth of table variable stored in the memory—it was very well received by the community. Read complete article here: SQL SERVER – Difference TempTable and Table Variable – TempTable in Memory a Myth. [...]]]></description>
		<content:encoded><![CDATA[<p>[...] December 28, 2009 by pinaldave    Few days ago I wrote an article on the myth of table variable stored in the memory—it was very well received by the community. Read complete article here: SQL SERVER – Difference TempTable and Table Variable – TempTable in Memory a Myth. [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ashu Goel</title>
		<link>http://blog.sqlauthority.com/2009/12/15/sql-server-difference-temptable-and-table-variable-temptable-in-memory-a-myth/#comment-58925</link>
		<dc:creator><![CDATA[Ashu Goel]]></dc:creator>
		<pubDate>Wed, 23 Dec 2009 03:30:54 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=7544#comment-58925</guid>
		<description><![CDATA[Used temp (#) in this procedure. Check it out...


alter procedure sp_Insert
(
   @vStr varchar(max)
)
as

Begin

    Declare @GetLine varchar(max), @GetCol varchar(max)
   Declare @p int, @col1 varchar(30), @col2 varchar(30)


--  Select @maxid = max(InvID) from tblMaster1
--  Delete from tblDetail1 where lid = @maxid

    create table #temp1 (col1 varchar(20), col2 varchar(20))

  While (len(@vstr) !=0)
     Begin
				if (len(@vstr) !=0 and charindex(&#039;^^&#039;,@vstr,0) = 0)
					Begin
						set @getline = @vstr
						set @vstr = &#039;&#039;
					 End
				else
					Begin
					  Select @getline = substring(@vstr,0,charindex(&#039;^^&#039;,@vstr,0))              
					End  
	       
				set @p = 0
	        
         While (len(@getline)!=0)
             Begin
				if (len(@getline) !=0 and charindex(&#039;^&#039;,@getline,0) = 0)
					 Begin
					   set @getcol=@getline
					   set @getline=&#039;&#039;
                       
					 End
                Else
                     Begin
                        print @getline
                        Select @getCol = substring(@getline,0,charindex(&#039;^&#039;,@getline,0)) 
                        print @getcol
                        
                     End
                set @P=@P+1            
                IF(@p=1)
                    begin
               
                       set @col1= @getcol
                       
                    end

                 if (@p=2)
                    begin
                       set @col2= @getcol
                        
                    end                  
                Set @getline = substring(@getline , charindex(&#039;^&#039; ,@getline,0)+1, len(@getline))
                print @getline
             End
 
--           Select @maxid= isnull(max(lid) from tbldet
               insert into #temp1 values(@col1,@col2)
             
 
          Set @vstr = substring(@vstr,charindex(&#039;^^&#039;,@vstr,0)+2 , len(@vstr))

     End
    
  Select * from #temp1

End]]></description>
		<content:encoded><![CDATA[<p>Used temp (#) in this procedure. Check it out&#8230;</p>
<p>alter procedure sp_Insert<br />
(<br />
   @vStr varchar(max)<br />
)<br />
as</p>
<p>Begin</p>
<p>    Declare @GetLine varchar(max), @GetCol varchar(max)<br />
   Declare @p int, @col1 varchar(30), @col2 varchar(30)</p>
<p>&#8211;  Select @maxid = max(InvID) from tblMaster1<br />
&#8211;  Delete from tblDetail1 where lid = @maxid</p>
<p>    create table #temp1 (col1 varchar(20), col2 varchar(20))</p>
<p>  While (len(@vstr) !=0)<br />
     Begin<br />
				if (len(@vstr) !=0 and charindex(&#8216;^^&#8217;,@vstr,0) = 0)<br />
					Begin<br />
						set @getline = @vstr<br />
						set @vstr = &#8221;<br />
					 End<br />
				else<br />
					Begin<br />
					  Select @getline = substring(@vstr,0,charindex(&#8216;^^&#8217;,@vstr,0))<br />
					End  </p>
<p>				set @p = 0</p>
<p>         While (len(@getline)!=0)<br />
             Begin<br />
				if (len(@getline) !=0 and charindex(&#8216;^&#8217;,@getline,0) = 0)<br />
					 Begin<br />
					   set @getcol=@getline<br />
					   set @getline=&#8221;</p>
<p>					 End<br />
                Else<br />
                     Begin<br />
                        print @getline<br />
                        Select @getCol = substring(@getline,0,charindex(&#8216;^&#8217;,@getline,0))<br />
                        print @getcol</p>
<p>                     End<br />
                set @P=@P+1<br />
                IF(@p=1)<br />
                    begin</p>
<p>                       set @col1= @getcol</p>
<p>                    end</p>
<p>                 if (@p=2)<br />
                    begin<br />
                       set @col2= @getcol</p>
<p>                    end<br />
                Set @getline = substring(@getline , charindex(&#8216;^&#8217; ,@getline,0)+1, len(@getline))<br />
                print @getline<br />
             End</p>
<p>&#8211;           Select @maxid= isnull(max(lid) from tbldet<br />
               insert into #temp1 values(@col1,@col2)</p>
<p>          Set @vstr = substring(@vstr,charindex(&#8216;^^&#8217;,@vstr,0)+2 , len(@vstr))</p>
<p>     End</p>
<p>  Select * from #temp1</p>
<p>End</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kuldip.Bhatt</title>
		<link>http://blog.sqlauthority.com/2009/12/15/sql-server-difference-temptable-and-table-variable-temptable-in-memory-a-myth/#comment-58898</link>
		<dc:creator><![CDATA[Kuldip.Bhatt]]></dc:creator>
		<pubDate>Tue, 22 Dec 2009 10:11:31 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=7544#comment-58898</guid>
		<description><![CDATA[Hello sir,
Great Topic to Discuss on blog.
good explanation with example and very useful too.

Ramdas has also give very good comment and very good explanation.]]></description>
		<content:encoded><![CDATA[<p>Hello sir,<br />
Great Topic to Discuss on blog.<br />
good explanation with example and very useful too.</p>
<p>Ramdas has also give very good comment and very good explanation.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nilay</title>
		<link>http://blog.sqlauthority.com/2009/12/15/sql-server-difference-temptable-and-table-variable-temptable-in-memory-a-myth/#comment-58804</link>
		<dc:creator><![CDATA[Nilay]]></dc:creator>
		<pubDate>Fri, 18 Dec 2009 14:36:52 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=7544#comment-58804</guid>
		<description><![CDATA[I have tried the sequences and it worked ,but when i drop temp #TempTable the user_objects_alloc_page_count did not clear to 0 ,WHY?]]></description>
		<content:encoded><![CDATA[<p>I have tried the sequences and it worked ,but when i drop temp #TempTable the user_objects_alloc_page_count did not clear to 0 ,WHY?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Pinal Dave</title>
		<link>http://blog.sqlauthority.com/2009/12/15/sql-server-difference-temptable-and-table-variable-temptable-in-memory-a-myth/#comment-58737</link>
		<dc:creator><![CDATA[Pinal Dave]]></dc:creator>
		<pubDate>Wed, 16 Dec 2009 19:44:41 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=7544#comment-58737</guid>
		<description><![CDATA[Hello Phani,

In case of large amount of data temp table is advised because sql server creates, maintains and uses the statistics of temp table while generating the execution plan. Besides this we can create index in tenp tables if that is needed.

Regards,
Pinal Dave]]></description>
		<content:encoded><![CDATA[<p>Hello Phani,</p>
<p>In case of large amount of data temp table is advised because sql server creates, maintains and uses the statistics of temp table while generating the execution plan. Besides this we can create index in tenp tables if that is needed.</p>
<p>Regards,<br />
Pinal Dave</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ramdas</title>
		<link>http://blog.sqlauthority.com/2009/12/15/sql-server-difference-temptable-and-table-variable-temptable-in-memory-a-myth/#comment-58723</link>
		<dc:creator><![CDATA[Ramdas]]></dc:creator>
		<pubDate>Wed, 16 Dec 2009 15:44:01 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=7544#comment-58723</guid>
		<description><![CDATA[Hi Phani,
In the comments section i have attempted to throw some light on the questions you have, look at the reply for tejas shah in the comments section.

Thank you]]></description>
		<content:encoded><![CDATA[<p>Hi Phani,<br />
In the comments section i have attempted to throw some light on the questions you have, look at the reply for tejas shah in the comments section.</p>
<p>Thank you</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Phani</title>
		<link>http://blog.sqlauthority.com/2009/12/15/sql-server-difference-temptable-and-table-variable-temptable-in-memory-a-myth/#comment-58687</link>
		<dc:creator><![CDATA[Phani]]></dc:creator>
		<pubDate>Wed, 16 Dec 2009 04:01:17 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=7544#comment-58687</guid>
		<description><![CDATA[Hi Pinal,

Thanks for the explanation. Have couple of questions haunting me now:

1. If both reside in tempDB, how are table variables different from temp tables? What is the advantage of using table variables in place of temp tables?
2. Why is it adviced to go for temporary tables when there is huge amount of data being stored in table variables?

Request you to throw some light on this to make things more clear which would help us in better understanding on each of these at concept and usability level.

Thanks for all your knowledge sharing.

Regards,
Phani.]]></description>
		<content:encoded><![CDATA[<p>Hi Pinal,</p>
<p>Thanks for the explanation. Have couple of questions haunting me now:</p>
<p>1. If both reside in tempDB, how are table variables different from temp tables? What is the advantage of using table variables in place of temp tables?<br />
2. Why is it adviced to go for temporary tables when there is huge amount of data being stored in table variables?</p>
<p>Request you to throw some light on this to make things more clear which would help us in better understanding on each of these at concept and usability level.</p>
<p>Thanks for all your knowledge sharing.</p>
<p>Regards,<br />
Phani.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Geetika</title>
		<link>http://blog.sqlauthority.com/2009/12/15/sql-server-difference-temptable-and-table-variable-temptable-in-memory-a-myth/#comment-58677</link>
		<dc:creator><![CDATA[Geetika]]></dc:creator>
		<pubDate>Tue, 15 Dec 2009 19:29:10 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=7544#comment-58677</guid>
		<description><![CDATA[Okay, got you. Many Thanks.]]></description>
		<content:encoded><![CDATA[<p>Okay, got you. Many Thanks.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: pinaldave</title>
		<link>http://blog.sqlauthority.com/2009/12/15/sql-server-difference-temptable-and-table-variable-temptable-in-memory-a-myth/#comment-58676</link>
		<dc:creator><![CDATA[pinaldave]]></dc:creator>
		<pubDate>Tue, 15 Dec 2009 19:05:48 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=7544#comment-58676</guid>
		<description><![CDATA[Please note that number 6 and 12 really does not matter. 

What matters is from 0 to 6 and 6 to 12 so in fact I am talking about they have same difference.]]></description>
		<content:encoded><![CDATA[<p>Please note that number 6 and 12 really does not matter. </p>
<p>What matters is from 0 to 6 and 6 to 12 so in fact I am talking about they have same difference.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Geetika</title>
		<link>http://blog.sqlauthority.com/2009/12/15/sql-server-difference-temptable-and-table-variable-temptable-in-memory-a-myth/#comment-58675</link>
		<dc:creator><![CDATA[Geetika]]></dc:creator>
		<pubDate>Tue, 15 Dec 2009 18:49:06 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=7544#comment-58675</guid>
		<description><![CDATA[I did not understand how the page count 6 and 12 for temp table and table variable resp shows that both uses tempdb. Can anyone explain this? Thanks.]]></description>
		<content:encoded><![CDATA[<p>I did not understand how the page count 6 and 12 for temp table and table variable resp shows that both uses tempdb. Can anyone explain this? Thanks.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

