Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 is this query correct?

Author  Topic 

saranrosy85@gmail.com
Starting Member

3 Posts

Posted - 2008-09-21 : 10:18:41
Please correct this query.This query is to copy the structure of a table and insert into another table.

insert into tablename(select * from xxx)values

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-09-21 : 10:31:15
[code]
insert into tablename (<column list> (
select (<column list>
from xxx ) values[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

GilaMonster
Master Smack Fu Yak Hacker

4507 Posts

Posted - 2008-09-21 : 10:51:30
If you want to create the table with the insert, then

select * into tablename from xxx

--
Gail Shaw
SQL Server MVP
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-09-21 : 13:02:32
quote:
Originally posted by saranrosy85@gmail.com

Please correct this query.This query is to copy the structure of a table and insert into another table.

insert into tablename(select * from xxx)values




if you want to copy the structure only just use modified form of query suggested by GilaMonster

select top 0 * into tablename from xxx




Go to Top of Page

raky
Aged Yak Warrior

767 Posts

Posted - 2008-09-22 : 00:34:36
quote:
Originally posted by saranrosy85@gmail.com

Please correct this query.This query is to copy the structure of a table and insert into another table.

insert into tablename(select * from xxx)values





Your query is incorrect.You can follow this query also to copy only the structure but not data of parent table

select * into <NewTable> from <Oldtable> where 1 = 0
Go to Top of Page
   

- Advertisement -