Solved

Default values creating table with SELECT * INTO

Posted on 2013-06-07
3
530 Views
Last Modified: 2013-06-08
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
0
Comment
Question by:formi
3 Comments
 
LVL 6

Assisted Solution

by:Peter Kiprop
Peter Kiprop earned 167 total points
ID: 39228739
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
 
LVL 75

Accepted Solution

by:
Anthony Perkins earned 166 total points
ID: 39230833
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
 
LVL 21

Assisted Solution

by:Alpesh Patel
Alpesh Patel earned 167 total points
ID: 39231095
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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question