<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>SQL 2000 to SQL 2005 migration: temporary tables reuse issue.</title><link>http://blogs.msdn.com/ikovalenko/archive/2007/04/28/sql-2000-to-sql-2005-migration-temporary-tables-reuse-issue.aspx</link><description>During the same project the next issue was found: temporary table reuse. Here is an example on “how to reproduce”: USE tempdb GO CREATE PROCEDURE dbo.usp_step_one AS BEGIN CREATE TABLE #temp (ID INT NOT NULL, NUM INT) ALTER TABLE #temp ADD CONSTRAINT</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>re: SQL 2000 to SQL 2005 migration: temporary tables reuse issue.</title><link>http://blogs.msdn.com/ikovalenko/archive/2007/04/28/sql-2000-to-sql-2005-migration-temporary-tables-reuse-issue.aspx#2318617</link><pubDate>Sun, 29 Apr 2007 04:33:35 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:2318617</guid><dc:creator>Kris</dc:creator><description>&lt;p&gt;What are table variables? Can you elaborate on that.&lt;/p&gt;
&lt;p&gt;Thanks.&lt;/p&gt;</description></item><item><title>re: SQL 2000 to SQL 2005 migration: temporary tables reuse issue.</title><link>http://blogs.msdn.com/ikovalenko/archive/2007/04/28/sql-2000-to-sql-2005-migration-temporary-tables-reuse-issue.aspx#2331518</link><pubDate>Mon, 30 Apr 2007 01:53:50 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:2331518</guid><dc:creator>Igor Kovalenko</dc:creator><description>&lt;p&gt;I meen you may try to use something like that&lt;/p&gt;
&lt;p&gt;declare @temp TABLE &amp;nbsp;(ID INT NOT NULL PRIMARY KEY, NUM INT)&lt;/p&gt;</description></item><item><title>re: SQL 2000 to SQL 2005 migration: temporary tables reuse issue.</title><link>http://blogs.msdn.com/ikovalenko/archive/2007/04/28/sql-2000-to-sql-2005-migration-temporary-tables-reuse-issue.aspx#3425300</link><pubDate>Wed, 20 Jun 2007 17:29:51 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:3425300</guid><dc:creator>Mike</dc:creator><description>&lt;p&gt;We ran into the same thing in our production code. I was nasty to trace because they were nested stored procedures using the same #table name with differing schema (not my design). &amp;nbsp;The whole thing makes seems analogous to c# and garbage - delayed.&lt;/p&gt;</description></item><item><title>re: SQL 2000 to SQL 2005 migration: temporary tables reuse issue.</title><link>http://blogs.msdn.com/ikovalenko/archive/2007/04/28/sql-2000-to-sql-2005-migration-temporary-tables-reuse-issue.aspx#4206096</link><pubDate>Fri, 03 Aug 2007 14:44:31 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:4206096</guid><dc:creator>Fitzer</dc:creator><description>&lt;p&gt;Rather than use a primary key , consider using a clustered key and precede the name with &amp;nbsp;a #&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;CREATE CLUSTERED INDEX [#temp_CIDX] ON #temp&lt;/p&gt;
&lt;p&gt;(&lt;/p&gt;
&lt;p&gt;	[ID] ASC &lt;/p&gt;
&lt;p&gt;)WITH (SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF) ON [PRIMARY]&lt;/p&gt;
&lt;p&gt;You will not have the Primary key constraint feature but you will have the benefit from indexing and stats.&lt;/p&gt;
</description></item><item><title>re: SQL 2000 to SQL 2005 migration: temporary tables reuse issue.</title><link>http://blogs.msdn.com/ikovalenko/archive/2007/04/28/sql-2000-to-sql-2005-migration-temporary-tables-reuse-issue.aspx#6770596</link><pubDate>Fri, 14 Dec 2007 18:28:08 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:6770596</guid><dc:creator>Ryan</dc:creator><description>&lt;p&gt;Great suggestion. &amp;nbsp;I had this same issue however unfortunately for me the additional challenge that my clustered PK key had to be on 2 columns, in which case you do have to name the constraint. &amp;nbsp;In order to avoid a naming conflict for that constraint my solution was to dynamically execute the DDL code to create the table, this way I created a unique constraint name on the fly. &amp;nbsp;You have to run dynamic sql, but sometimes that's just what works. &amp;nbsp;You'll end up with your PK constraint and no naming conflicts.&lt;/p&gt;
&lt;p&gt;DECLARE @CreateString nvarchar(512)&lt;/p&gt;
&lt;p&gt;SET @CreateString = N'CREATE TABLE ##temp&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;([ID_ONE] int NOT NULL, [ID_TWO] int NOT NULL, [NUM] int,&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;CONSTRAINT [PK_ID_' + Cast(NEWID() as nvarchar(50)) + '] PRIMARY KEY CLUSTERED &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;([ID_ONE], [ID_TWO]) WITH (IGNORE_DUP_KEY = OFF)) ON [PRIMARY]'&lt;/p&gt;
&lt;p&gt;exec sp_executesql @CreateString&lt;/p&gt;</description></item></channel></rss>