Friday, September 6, 2019

Copy-table-structure-or-Data

Below code provide information creating new table as a replica from existing table or to create structure with similar data.

Such situation occurs when one try to take backup of existing DB table or Table with Data

1) Creating blank structure from existing table

--Execute on sql prompt

begin
  execute immediate 'create table emp1 as select * from emp where 1=2';
end;

--Execute on sql prompt
select count(1) from emp1;


2) Creating structure from existing table with data

--Execute on sql prompt
begin
  execute immediate 'create table emp1 as select * from emp';
end;

--Execute on sql prompt

select count(1) from emp1;

No comments:

Post a Comment