SQL Clone Table



The SQL clone table may be used in a situation that you need an exact copy of a table and CREATE TABLE … SELECT doesn’t suit your purposes because the copy must include the same indexes, default values, and so forth.

You can handle this situation by following steps:

You can handle this situation by following steps:


Use SHOW CREATE TABLE to get a CREATE TABLE statement that specifies the source table’s structure, indexes and all.


Modify the statement to change the table name to that of the clone table and execute the statement. This way, you will have exact clone table.


Optionally, if you need the table contents copied as well, issue an INSERT INTO … SELECT statement, too.


Step 1:

Get complete structure about table.

  1. mysql> SHOW CREATE TABLE tutorials_tbl \G;
  2.        Table: tutorials_tbl
  3. Create Table: CREATE TABLE <code>tutorials_table</code> (
  4.   <code>tutorial_id</code> int(11) NOT NULL auto_increment,
  5.   <code>tutorial_Fname</code> varchar(10);
  6.   <code>tutorial_Lname</code> varchar(40) NOT NULL default '',
  7.   <code>submission_FEE</code> date default NULL,
  8.   PRIMARY KEY  (<code>tutorial_id</code>),
  9.   UNIQUE KEY <code>Person_Name</code> (<code>Person_Name </code>)
  10. ) TYPE=MINE
  11. 1 row in set (0.00 sec)
  13. ERROR:
  14. No query specified

Step 2:

Rename this table and create another table.

  1. mysql> CREATE TABLE <code>clone_table</code> (
  2.   -> <code>tutorial_id</code> int(11) NOT NULL auto_increment,
  3.     tutorial_id<code> int(11) NOT NULL auto_increment,
  4.    </code>tutorial_Fname<code> varchar(10);
  5.    </code>tutorial_Lname<code> varchar(40) NOT NULL default '',
  6.    </code> submission_FEE<code> date default NULL,
  8.   -> PRIMARY KEY  (</code>tutorial_id<code>),
  9.   UNIQUE KEY </code>Person_Name<code> (</code>Person_Name `)
  10. -> ) TYPE=MINE;
  11. Query OK, 0 rows affected (1.80 sec)

Step 3:

  1. mysql> INSERT INTO clone_tbl (tutorial_id,
  2.     ->                        tutorial_Fname,
  3.     ->                        tutorial_Lname,
  4.     ->                        submission_FEE
  5.     -> SELECT tutorial_id,tutorial_Fname,
  6.     ->        tutorial_Lname,submission_fee,
  7.     -> FROM tutorials_table;
  8. Query OK, 3 rows affected (0.07 sec)
  9. Records: 3  Duplicates: 0  Warnings: 0


You will have exact clone table as the user wished for.

Facebook Comments


  1. magnificent publish, very informative. I wonder why the opposite specialists of this sector don’t notice this. You must continue your writing. I am confident, you’ve a huge readers’ base already!

  2. Nos actualizamos tanto como el sector nos ofrece, estamos pendientes de las ultimos novedades de productos para Sex Shop de este modo logramos estar en los sitios punteros y ser referente de contar con todas las novedades.


Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.