Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Default values creating table with SELECT * INTO

Posted on 2013-06-07
3
Medium Priority
?
553 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 6

Assisted Solution

by:Peter Kiprop
Peter Kiprop earned 501 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 498 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 501 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

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

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.
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

609 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