Solved

Default values creating table with SELECT * INTO

Posted on 2013-06-07
3
526 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
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.

759 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now