SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


"CTAS" in SQL Server


"CTAS" in SQL Server

Author
Message
orasqldba
orasqldba
Valued Member
Valued Member (73 reputation)Valued Member (73 reputation)Valued Member (73 reputation)Valued Member (73 reputation)Valued Member (73 reputation)Valued Member (73 reputation)Valued Member (73 reputation)Valued Member (73 reputation)

Group: General Forum Members
Points: 73 Visits: 31
Hi, There is something called "CTAS" create table as in Oracle and was wondering if there was anything like that in SQL 2000.

I am a newbie to SQL.

In Oracle you can do the following..

create table my.test
as
select * from your.test;

also

insert into my.test
select * from your.test;

Your help in much appreciated...all this excercise is to put some load a DB server, by CTAS'ng a big table.

Thanks in Advance
Ramki
Matt Miller (4)
Matt Miller (4)
SSC Guru
SSC Guru (67K reputation)SSC Guru (67K reputation)SSC Guru (67K reputation)SSC Guru (67K reputation)SSC Guru (67K reputation)SSC Guru (67K reputation)SSC Guru (67K reputation)SSC Guru (67K reputation)

Group: General Forum Members
Points: 67880 Visits: 19993
Look at using Select ... INTO


Example:

Select *
INTO MyNewTable
from MyOldTable

Uses whatever it derives from the query to make a table.

----------------------------------------------------------------------------------
Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?
RBarryYoung
RBarryYoung
SSC Guru
SSC Guru (80K reputation)SSC Guru (80K reputation)SSC Guru (80K reputation)SSC Guru (80K reputation)SSC Guru (80K reputation)SSC Guru (80K reputation)SSC Guru (80K reputation)SSC Guru (80K reputation)

Group: General Forum Members
Points: 80102 Visits: 9519
Matt Miller (3/12/2008)
Look at using Select ... INTO


Example:

Select *
INTO MyNewTable
from MyOldTable

Uses whatever it derives from the query to make a table.

And if you want to "Create As" like this but without any data:
Select *
INTO MyNewTable
from MyOldTable
Where 0=1



-- RBarryYoung, (302)375-0451 blog: MovingSQL.com, Twitter: @RBarryYoung
Proactive Performance Solutions, Inc.
"Performance is our middle name."
orasqldba
orasqldba
Valued Member
Valued Member (73 reputation)Valued Member (73 reputation)Valued Member (73 reputation)Valued Member (73 reputation)Valued Member (73 reputation)Valued Member (73 reputation)Valued Member (73 reputation)Valued Member (73 reputation)

Group: General Forum Members
Points: 73 Visits: 31
Thankyou!
Scalability Doug
Scalability Doug
Hall of Fame
Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)

Group: General Forum Members
Points: 3247 Visits: 6111
There are 2 differences between SELECT INTO and INSERT INTO...

SELECT INTO only works for if the inserted table does not exist. INSERT INTO works if the inserted table already exists.


DAB
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum








































































































































































SQLServerCentral


Search