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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Create with Select

Author  Topic 

subashmvs
Starting Member

4 Posts

Posted - 2008-03-12 : 06:42:14
hi,

when I try the following query an error is ocuured

CREATE TABLE tb1 AS ( SELECT * FROM Tab2 )

Is it not support in SQL Server 2005?

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2008-03-12 : 06:43:05
[code]Select * into tb1 from tab2[/code]

[EDIT] Note that for large tables this is not recommended.

Instead you can script of tab2, rename table name to tb1, execute the script to create table and use regular INSERT statement to populate data.

Also note that, above statement won't copy the indexes and other constraints which exists on original table.
[END EDIT]

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-03-12 : 06:51:12
To avoid locks on source table, try

select top 0 * into tb1 from tab2
insert tb1 select * from tab2



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

subashmvs
Starting Member

4 Posts

Posted - 2008-03-12 : 06:53:24
thanx harsh...
its very informative..
becoz i am femiliar in oracle Query, not much in SQL server
Go to Top of Page
   

- Advertisement -