﻿<?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 2008 / T-SQL (SS2K8)  / SELECT * INTO Table without propagating IDENTITY attribute? / 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>Sat, 25 May 2013 03:23:28 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: SELECT * INTO Table without propagating IDENTITY attribute?</title><link>http://www.sqlservercentral.com/Forums/Topic1400640-392-1.aspx</link><description>Thank you, Scott! With the addition of a WHERE clause on the first SELECT, I end up with an empty table without a IDENTITY property, which is EXACTLY what I was looking for. Prefacing the * with my additional control columns doesn't mess up the solution, either. SSC rules!</description><pubDate>Thu, 03 Jan 2013 09:22:07 GMT</pubDate><dc:creator>PhilPacha</dc:creator></item><item><title>RE: SELECT * INTO Table without propagating IDENTITY attribute?</title><link>http://www.sqlservercentral.com/Forums/Topic1400640-392-1.aspx</link><description>[quote][b]Jeff Moden (12/27/2012)[/b][hr][quote][b]PhilPacha (12/27/2012)[/b][hr]Using the simplest SELECT INTO syntax, the IDENTITY property of a column is part of the definition of the destination table. Is there a simple way to avoid this? I can't seem to find anything in the documentation, or my google-foo is  deficient.I'm trying to create an mirror image of a table, using a false WHERE clause to create only the table structure.[/quote]It's easy.  Just recast the column as an INT during the SELECT/INTO.  If you want it to be a NOT NULL column, just wrap an ISNULL around that...[code="sql"] SELECT SomeBasicIntColumn = ISNULL(CAST(SomeIdentityColumn AS INT),0),        other columns   INTO #SomeTempTable   FROM dbo.SomeOtherTable  WHERE 1 = 0;[/code][/quote]You can also do this with an integer expression[code="sql"]SELECT SomeBasicIntColumn = 0 + SomeIdentityColumn,        other columns   INTO #SomeTempTable   FROM dbo.SomeOtherTable  WHERE 1 = 0[/code]</description><pubDate>Mon, 31 Dec 2012 16:29:16 GMT</pubDate><dc:creator>Mark-101232</dc:creator></item><item><title>RE: SELECT * INTO Table without propagating IDENTITY attribute?</title><link>http://www.sqlservercentral.com/Forums/Topic1400640-392-1.aspx</link><description>[quote][b]ScottPletcher (12/31/2012)[/b][hr]Please try this:[code="sql"]SELECT *INTO dbo.newtableFROM dbo.oldtable_with_identityUNION ALLSELECT TOP (1) *FROM dbo.oldtable_with_identityWHERE 1 = 0[/code]The identity property should be left off the column in the new table :-).[/quote]Nicely done, Scott.  You can also get away without using the TOP (1).  The cpu time used and the number of reads are identical.</description><pubDate>Mon, 31 Dec 2012 16:11:31 GMT</pubDate><dc:creator>Jeff Moden</dc:creator></item><item><title>RE: SELECT * INTO Table without propagating IDENTITY attribute?</title><link>http://www.sqlservercentral.com/Forums/Topic1400640-392-1.aspx</link><description>deleted</description><pubDate>Mon, 31 Dec 2012 15:27:33 GMT</pubDate><dc:creator>Jason Selburg</dc:creator></item><item><title>RE: SELECT * INTO Table without propagating IDENTITY attribute?</title><link>http://www.sqlservercentral.com/Forums/Topic1400640-392-1.aspx</link><description>Please try this:[code="sql"]SELECT *INTO dbo.newtableFROM dbo.oldtable_with_identityUNION ALLSELECT TOP (1) *FROM dbo.oldtable_with_identityWHERE 1 = 0[/code]The identity property should be left off the column in the new table :-).</description><pubDate>Mon, 31 Dec 2012 14:40:28 GMT</pubDate><dc:creator>ScottPletcher</dc:creator></item><item><title>RE: SELECT * INTO Table without propagating IDENTITY attribute?</title><link>http://www.sqlservercentral.com/Forums/Topic1400640-392-1.aspx</link><description>Thanks Jeff. I was hoping for something which could use "SELECT *", so knowledge about the extant columns wouldn't be necessary. Neat technique, though, if the column names and the column with the IDENTITY attribute are known in advance. I'll add this bit to my "tool box".</description><pubDate>Thu, 27 Dec 2012 08:53:44 GMT</pubDate><dc:creator>PhilPacha</dc:creator></item><item><title>RE: SELECT * INTO Table without propagating IDENTITY attribute?</title><link>http://www.sqlservercentral.com/Forums/Topic1400640-392-1.aspx</link><description>[quote][b]PhilPacha (12/27/2012)[/b][hr]Using the simplest SELECT INTO syntax, the IDENTITY property of a column is part of the definition of the destination table. Is there a simple way to avoid this? I can't seem to find anything in the documentation, or my google-foo is  deficient.I'm trying to create an mirror image of a table, using a false WHERE clause to create only the table structure.[/quote]It's easy.  Just recast the column as an INT during the SELECT/INTO.  If you want it to be a NOT NULL column, just wrap an ISNULL around that...[code="sql"] SELECT SomeBasicIntColumn = ISNULL(CAST(SomeIdentityColumn AS INT),0),        other columns   INTO #SomeTempTable   FROM dbo.SomeOtherTable  WHERE 1 = 0;[/code]</description><pubDate>Thu, 27 Dec 2012 08:46:40 GMT</pubDate><dc:creator>Jeff Moden</dc:creator></item><item><title>RE: SELECT * INTO Table without propagating IDENTITY attribute?</title><link>http://www.sqlservercentral.com/Forums/Topic1400640-392-1.aspx</link><description>What you described would create that mirror image. If you just not want to have the identity column in the new table, you can simply exclude it from the select list. [code]create table #Source(	SourceID int identity,	SomeValue varchar(10))insert #Sourceselect 'Source 1' union allselect 'Source 2'select * into #Test from #Sourcewhere 1 = 2insert #Testselect 'Test'select * from #Testdrop table #Sourcedrop table #Test[/code]</description><pubDate>Thu, 27 Dec 2012 08:42:06 GMT</pubDate><dc:creator>Sean Lange</dc:creator></item><item><title>RE: SELECT * INTO Table without propagating IDENTITY attribute?</title><link>http://www.sqlservercentral.com/Forums/Topic1400640-392-1.aspx</link><description>I want a clone of the table (with 3 addition, preceeding, columns), with the original column sequence, if possible. I'd rather not have to resort to dynamic SQL to define the table, but the presence of the IDENTITY attribute is a "deal killer", since the purpose is short-term "before / after" storage for content changes.</description><pubDate>Thu, 27 Dec 2012 08:41:29 GMT</pubDate><dc:creator>PhilPacha</dc:creator></item><item><title>RE: SELECT * INTO Table without propagating IDENTITY attribute?</title><link>http://www.sqlservercentral.com/Forums/Topic1400640-392-1.aspx</link><description>Why not drop the column after creation and before putting anything in it?</description><pubDate>Thu, 27 Dec 2012 08:37:05 GMT</pubDate><dc:creator>Jason Selburg</dc:creator></item><item><title>SELECT * INTO Table without propagating IDENTITY attribute?</title><link>http://www.sqlservercentral.com/Forums/Topic1400640-392-1.aspx</link><description>Using the simplest SELECT INTO syntax, the IDENTITY property of a column is part of the definition of the destination table. Is there a simple way to avoid this? I can't seem to find anything in the documentation, or my google-foo is  deficient.I'm trying to create an mirror image of a table, using a false WHERE clause to create only the table structure.</description><pubDate>Thu, 27 Dec 2012 08:35:36 GMT</pubDate><dc:creator>PhilPacha</dc:creator></item></channel></rss>