Solved

Create table as on SQL Server

Posted on 1998-10-29
3
214 Views
Last Modified: 2008-03-03
What's the syntax to do the following.

I do it on Oracle all the time!

create table temp as select * from other_table

This creates a new table temp with the same strucure and copies all the data into it.
Or I can do

create table temp as col1,col2,ect from other_table

Thanks...
0
Comment
Question by:fox_dogg
[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 3

Accepted Solution

by:
Stefaan earned 20 total points
ID: 1090893
Hi,

You were very close there, the correct Statemet for SQL Server 6.5 would be :

SELECT Col1, Col2, Col3
INTO <newTableName>
FROM <OriginalTableName>

SELECT INTO is a two-step operation.  

The first step creates the new table, so you have to make sure that the user who is executing this statement has the CREATE TABLE permission in the destination database.

The second step inserts the specified rows into the new table. If the second step fails for any reason (hardware failure, exceeding a system resource, and so on), the new table will exist but have no rows.

If you just want to create a new table with the same table definition, but with no records in it, you could use the same statement, and append a WHERE clausule which will always be false.  This way the first step will create the table, but no records will be inserted.

I think that this is what you are looking for.

Greetings and best regards,


Stefaan Lesage

0
 

Expert Comment

by:scarlett
ID: 1090894
Put a # in front of the new table name to make it a temporary table, i.e., #temp_table
0
 

Author Comment

by:fox_dogg
ID: 1090895
Thanks perfect!
0

Featured Post

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
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.

740 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