tags:

views:

94

answers:

4

In oracle, you can issue:

 create table foo as select * from bar;

What is the equivalent T-SQL statement?

+4  A: 

select * into foo from bar

Chad
+1 beat me to it...
Sani Huttunen
+2  A: 

You can use SELECT INTO. From MSDN:

The SELECT INTO statement creates a new table and populates it with the result set of the SELECT statement. SELECT INTO can be used to combine data from several tables or views into one table. It can also be used to create a new table that contains data selected from a linked server.

So:

SELECT col1, col2, col3 INTO newTable FROM existingTable;
Oded
+1  A: 

Chris,

If you want to write to the tempdb

Select *
INTO #tmp
From bar

or to a SQL DB

Select *
INTO Temp
From bar

S

scarpacci
A: 

CREATE TABLE FOO AS BAR;

GerardMcL