Solved

Default values creating table with SELECT * INTO

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
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.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

838 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