Default values creating table with SELECT * INTO

Hi

I habe a MS-SQL-Server database and create a table from another with
SELECT * INTO NewTableName FROM ExistingTableName WHERE 1 = 2

Open in new window

the table is created but without the default-value-settings. Is there a way to create the table this way (not with Create Table) and to have the default values too?
Thanks, Peter
formiAsked:
Who is Participating?
 
Anthony PerkinsCommented:
Is there a way to create the table this way (not with Create Table) and to have the default values too?
Default values is the least of your problems.  You will have the same problem with all your indexes, CONSTRAINTs (other than DEFAULT)

Also, you will find that INSERT INTO when it comes to performance is by far a better option than SELECT * INTO ...
0
 
Peter KipropCommented:
Hi, Peter,


There is no better way of doing this other than altering the table after insert  and setting the default settings for each field or using  create table, which is the best method.
0
 
Alpesh PatelAssistant ConsultantCommented:
In

Select * INTO

SQL server only ceate structure without any constrains.

It's better to create table first ad then use

Insert into Select * FROM syntax.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.