PhilPacha (12/27/2012)
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.
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...
SELECT SomeBasicIntColumn = ISNULL(CAST(SomeIdentityColumn AS INT),0),
other columns
INTO #SomeTempTable
FROM dbo.SomeOtherTable
WHERE 1 = 0
;
--Jeff Moden
Change is inevitable... Change for the better is not.