Loading, please wait...

Clone Table

How to use Clone Tables in SQL

 

Introduction:
In this article, you will learn what clone table is and how to use clone tables in SQL.

 

With the help of SQL clone, we can create a copy of the current table in SQL. This copy of the table must be same as the indexes and default values. If you want to create a clone table in SQL, first create a normal table.

 

Subsequently, create same as another table but with the different name and then execute this with Insert and Select command.

 

 

Example:

There are some steps to create a clone table.

 

Step 1: We will create a new table in our database. The syntax for creating a new table is as follows:

show create table table_name

 

create table table_name (

table_field datatype() NOT NULL ,

table_field datatype() NOT NULL ,

table_field datatype() NOT NULL ,

table_field datatype() ,

PRIMARY KEY ( table_field),

) ;

 

 

 

 

 

 

Step 2: Create the other similar table but with the different name. The syntax for creating a new table is as follows:

 

create table table_name (

table_field datatype() NOT NULL ,

table_field datatype() NOT NULL ,

table_field datatype() NOT NULL ,

table_field datatype() ,

PRIMARY KEY ( table_field),

) ;

 

 

 

Step 3: Now, we have a copy of Employee table in the same database. If we want to use other table data, apply Insert into a Select statement.

Insert into table_name (table_field 1, table_field 2,...........)

 

select table_field 1, table_field 2,........... from table_name;

 

 

 

Summary:

Thus, we learned that clone table is used to make the copy of the current table and also learn it's used in SQL.