Sunday, August 26, 2012

Create new tables in Oracle and SQL Server


In Oracle, we can use  "create table as select" as shown below.
1. Copy table into a new table.
create table tbl_x as select * from tbl_test;
2.Create a  new empty table with the same structure.
create table tbl_y as select * from tbl_test where 2=1;

In SQL Server,  we can use select into as shown below.
1. Copy table into a new table.
select * into  tbl_x   from  tbl_test ;
2. Create a  new empty table with the same structure.
select * into  tbl_y   from tbl_test  where 2=1;

No comments: