Wednesday, June 15, 2022

Oracle SQL Create Table Using Select Statement

 Create Table with Select Statement

We can create a table using existing table [along with data].

 

create table emp1 as select * from emp;

 

Creating table with your own column names.

 create table emp2 (empno,ename,job) as select * from emp;

Note: -in the above query two tables no. of columns must be same.

 

Creating table with specified columns.

create table emp3 as select empno,ename from emp;

 

Creating table without table data.

create table emp4 as select * From emp where 1 = 2;

 

  Note: In all databases whenever we are copying a table from another table internally constraints (Primary key, Foreign key) are never copied.

No comments:

Post a Comment