473,378 Members | 1,387 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Error while Creating table using Select Command

Hi All,

I am new to MS SQL Server.I am using MS SQL 2000.I have a problem in
creating a table by using Select command.I have table called "test"
and i want to create another table with the same structure and rows.I
tried with the following command

create Table test1 as select * from test;

But it give an syntax error.I have tried the same command in Oracle
but i was working.Does MS SQL 2000 Server supports this kind of Query.

Please help me to solve the problem or any other methods to perform
this operation.

Thanks in Advance

Kevin
Jul 20 '05 #1
2 22707
You can use Query Analyzer to generate the CREATE TABLE statement
automatically from your exsiting table.

CREATE TABLE test1 (col1 INTEGER PRIMARY KEY, col2...)

INSERT INTO test1 (col1, col2,...)
SELECT col1, col2,...
FROM test

You can also use:

SELECT * INTO test1 FROM test

but the CREATE... INSERT method gives you more control over constraints,
etc.

--
David Portas
------------
Please reply only to the newsgroup
--
Jul 20 '05 #2
SELECT * INTO NewTable FROM OldTable

This will create the same structure and take the data with it.

The other option is go to the design of your table, preview a script
of it, and then use this to build the new table (just change the table
name). Once you have the structure of the table, you can create / drop
this as needed within your query (i.e. Create Table ... SELECT
INTO...)

"David Portas" <RE****************************@acm.org> wrote in message news:<hr********************@giganews.com>...
You can use Query Analyzer to generate the CREATE TABLE statement
automatically from your exsiting table.

CREATE TABLE test1 (col1 INTEGER PRIMARY KEY, col2...)

INSERT INTO test1 (col1, col2,...)
SELECT col1, col2,...
FROM test

You can also use:

SELECT * INTO test1 FROM test

but the CREATE... INSERT method gives you more control over constraints,
etc.

Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Indraneel Sheorey | last post by:
Hello, I want to set up a query in SQL Server that is "grouped by" a variable PRICE. Since PRICE takes on continuous decimal values, I want to create deciles based on this variable and then...
7
by: p | last post by:
WE had a Crystal 8 WebApp using vs 2002 which we upgraded to VS2003. I also have Crystal 9 pro on my development machine. The web app runs fine on my dev machine but am having problems deploying....
9
by: Patrick.O.Ige | last post by:
I have a code below and its a PIE & BAR CHART. The values now are all static but I want to be able to pull the values from a database. Can you guys give me some ideas to do this? Thanks ...
1
by: cindy | last post by:
Get data into datatable, add to dataset dsSearch " Get data into datatable, add to dataset dsSearch Using In-Memory SQL Engine join the tables and select the filenames from the join, add to...
10
by: cj | last post by:
I have lots of tables to copy from one server to another. The new tables have been created to match the old ones. I practiced with one table. I created the select command (select * from tableA)...
0
by: DC | last post by:
The problem I'm using the .NET GridView and FormView objects for the first time and im getting the error "An OleDbParameter with ParameterName '@ID' is not contained by this...
7
by: Arun Srinivasan | last post by:
I have a problem, I am getting SQL1042N The SQL statement is not supported. error when I try to create a MQT against a nickname. The source db is db2 version 9.1 fixpack 4, same as the target db...
2
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
0
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.