Groups | Blog | Home
all groups > sql server (alternate) > october 2004 >

sql server (alternate) : Select * into removes defaults


gelangov NO[at]SPAM hotmail.com
10/21/2004 12:57:02 PM
I have a table, tbl1:
create table tbl1 ([field1] [char] (16) NULL DEFAULT (' '),
[field2] [char] (6) NULL DEFAULT (' ')).

When I do a select * into tbl2 from tbl1, tbl2 does not have defaults.
Is there any settings I have to keep on when I do a select * into?
Hugo Kornelis
10/21/2004 10:17:51 PM
[quoted text, click to view]

Hi Geetha,

SELECT ... INTO <tablename> creates a new table and fills it with the data
returned by the SELECT statement (which might come from zero, 1 or many
more tables). It doesn't define any constraints (like PRIMARY KEY, UNIQUE,
FOREIGN KEY, CHECK, NOT NULL) or properties (like DEFAULT or IDENTITY) for
the new table.

You must either create the table with CREATE TABLE first, including all
constraints and properties, then populate it with "INSERT INTO <tablename>
(column list) SELECT ...", or you keep the "SELECT ... INTO <tablename"
and use ALTER TABLE to add the constraints and properties.

Best, Hugo
--

gelangov NO[at]SPAM hotmail.com
10/22/2004 5:59:11 AM
Thanks, Hugo!

[quoted text, click to view]
AddThis Social Bookmark Button