0% found this document useful (0 votes)
4 views1 page

6 +Different+ways+to+make+a+copy+of+a+Table

The document provides SQL commands for creating a copy of an existing table named 'employees' using various methods. It demonstrates creating a new table, inserting data, and using 'CREATE TABLE AS SELECT', 'CLONE', and 'LIKE' keywords to replicate the original table. The document also includes example data entries for the 'new_employees' table.

Uploaded by

tokixit492
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views1 page

6 +Different+ways+to+make+a+copy+of+a+Table

The document provides SQL commands for creating a copy of an existing table named 'employees' using various methods. It demonstrates creating a new table, inserting data, and using 'CREATE TABLE AS SELECT', 'CLONE', and 'LIKE' keywords to replicate the original table. The document also includes example data entries for the 'new_employees' table.

Uploaded by

tokixit492
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

---------------------- COPY TABLE ----------------------

-- How to create a copy of existing table?

create or replace table new_employees(employee_id number,


empl_join_date date,
dept varchar(10),
salary number,
manager_id number);

insert into new_employees values(8,'2014-10-01','HR',40000,4),


(12,'2014-09-01','Tech',50000,9),
(3,'2018-09-01','Marketing',30000,5),
(4,'2017-09-01','HR',10000,5),
(25,'2019-09-01','HR',35000,9),
(12,'2014-09-01','Tech',50000,9),
(86,'2015-09-01','Tech',90000,4),
(73,'2016-09-01','Marketing',20000,1);

-------- using CREATE TABLE AS SELECT --------- <Also referred as CTAS>


--drop table employees;
create or replace table employees as select * from new_employees;

insert into employees select * from new_employees;

select * from employees;

------------ using CLONE keyword ------------


CREATE OR REPLACE TABLE employees_clone CLONE employees;

select * from employees_clone;

------------ using LIKE keyword ------------


CREATE OR REPLACE TABLE employees_like LIKE employees;

select * from employees_like;

You might also like