SlideShare a Scribd company logo
http://www.tutorialspoint.com/mysql/mysql-clone-tables.htm Copyright © tutorialspoint.com
MYSQL CLONE TABLESMYSQL CLONE TABLES
There may be a situation when 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:
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.
Example:
Try out the following example to create a clone table for tutorials_tbl.
Step 1:
Get complete structure about table.
mysql> SHOW CREATE TABLE tutorials_tbl G;
*************************** 1. row ***************************
Table: tutorials_tbl
Create Table: CREATE TABLE `tutorials_tbl` (
`tutorial_id` int(11) NOT NULL auto_increment,
`tutorial_title` varchar(100) NOT NULL default '',
`tutorial_author` varchar(40) NOT NULL default '',
`submission_date` date default NULL,
PRIMARY KEY (`tutorial_id`),
UNIQUE KEY `AUTHOR_INDEX` (`tutorial_author`)
) TYPE=MyISAM
1 row in set (0.00 sec)
ERROR:
No query specified
Step 2:
Rename this table and create another table.
mysql> CREATE TABLE `clone_tbl` (
-> `tutorial_id` int(11) NOT NULL auto_increment,
-> `tutorial_title` varchar(100) NOT NULL default '',
-> `tutorial_author` varchar(40) NOT NULL default '',
-> `submission_date` date default NULL,
-> PRIMARY KEY (`tutorial_id`),
-> UNIQUE KEY `AUTHOR_INDEX` (`tutorial_author`)
-> ) TYPE=MyISAM;
Query OK, 0 rows affected (1.80 sec)
Step 3:
After executing step 2, you will create a clone table in your database. If you want to copy data from
old table then you can do it by using INSERT INTO... SELECT statement.
mysql> INSERT INTO clone_tbl (tutorial_id,
-> tutorial_title,
-> tutorial_author,
-> submission_date)
-> SELECT tutorial_id,tutorial_title,
-> tutorial_author,submission_date,
-> FROM tutorials_tbl;
Query OK, 3 rows affected (0.07 sec)
Records: 3 Duplicates: 0 Warnings: 0
Finally, you will have exact clone table as you wanted to have.

More Related Content

What's hot (20)

TXT
Spss syntax
rohit vishwakarma
 
PPTX
Oracle: PLSQL Introduction
DataminingTools Inc
 
PPT
Les10
arnold 7490
 
PPTX
Oracle views
Balqees Al.Mubarak
 
DOC
Sql
krishna_v111
 
PPTX
Lab2 ddl commands
Balqees Al.Mubarak
 
PPT
SQL select clause
arpit bhadoriya
 
PDF
Cursors in MySQL
Tharindu Weerasinghe
 
PPTX
Sql server ___________session_16(views)
Ehtisham Ali
 
PDF
View & index in SQL
Swapnali Pawar
 
PPT
Oracle training in hyderabad
Kelly Technologies
 
PPT
Les09
arnold 7490
 
PPTX
Oracle: DML
DataminingTools Inc
 
PPT
Les02
Sudharsan S
 
RTF
Trigger and cursor program using sql
Sushil Mishra
 
ODP
Prabu's sql quries
Prabu Cse
 
ODP
My sql Syntax
Reka
 
PPT
4 trigger
Trần Thanh
 
Spss syntax
rohit vishwakarma
 
Oracle: PLSQL Introduction
DataminingTools Inc
 
Oracle views
Balqees Al.Mubarak
 
Lab2 ddl commands
Balqees Al.Mubarak
 
SQL select clause
arpit bhadoriya
 
Cursors in MySQL
Tharindu Weerasinghe
 
Sql server ___________session_16(views)
Ehtisham Ali
 
View & index in SQL
Swapnali Pawar
 
Oracle training in hyderabad
Kelly Technologies
 
Oracle: DML
DataminingTools Inc
 
Trigger and cursor program using sql
Sushil Mishra
 
Prabu's sql quries
Prabu Cse
 
My sql Syntax
Reka
 
4 trigger
Trần Thanh
 

Viewers also liked (20)

PPTX
Grooming standards
Dr. Sunil Kumar
 
PPT
Grooming accesories
Imprint Training Center
 
PDF
Presentation ECN
Nadia Ayala
 
DOCX
RESUME
Katie Berg
 
PPTX
P&G
Aayush Chugh
 
PPTX
Каждому "свой " вид спорта - работа ученицы 5 «А» класса МБОУ Школы № 70 Си...
School70_Samara
 
PDF
Official Campus Eye Slide Deck
Garrett Foley
 
PPT
CONOTEL - Congresso Nacional de Hotéis
TEKNERGIA
 
PDF
Bo si do bo --- http://xuongmayquanaokn.com/
xưởng may KN
 
PPT
BlueBRIDGE: Cloud infrastructure serving aquafarms and supporting models
Blue BRIDGE
 
PPTX
Virtual Research Environments supporting tailor-made data management service...
Blue BRIDGE
 
PPT
Grooming
Shan Sachwani
 
DOC
Gubendran Lakshmanan
Gubendran Lakshmanan
 
PPTX
GROOMING ASSIGNMENT
Sumaiyya Sardar
 
PPT
Grooming at workplace
Ravi Kumar
 
PPT
Personal Grooming
MMMTS
 
PPTX
Frankfinn Grooming Presentation ...
Syed Shabbir Hussain
 
PPT
Frankfinn Grooming Presentation
ryan dias
 
PPTX
Grooming PPT Frankfinn
Harsh Soni
 
PPTX
funditpresFINAL
Victoria Muldowney
 
Grooming standards
Dr. Sunil Kumar
 
Grooming accesories
Imprint Training Center
 
Presentation ECN
Nadia Ayala
 
RESUME
Katie Berg
 
Каждому "свой " вид спорта - работа ученицы 5 «А» класса МБОУ Школы № 70 Си...
School70_Samara
 
Official Campus Eye Slide Deck
Garrett Foley
 
CONOTEL - Congresso Nacional de Hotéis
TEKNERGIA
 
Bo si do bo --- http://xuongmayquanaokn.com/
xưởng may KN
 
BlueBRIDGE: Cloud infrastructure serving aquafarms and supporting models
Blue BRIDGE
 
Virtual Research Environments supporting tailor-made data management service...
Blue BRIDGE
 
Grooming
Shan Sachwani
 
Gubendran Lakshmanan
Gubendran Lakshmanan
 
GROOMING ASSIGNMENT
Sumaiyya Sardar
 
Grooming at workplace
Ravi Kumar
 
Personal Grooming
MMMTS
 
Frankfinn Grooming Presentation ...
Syed Shabbir Hussain
 
Frankfinn Grooming Presentation
ryan dias
 
Grooming PPT Frankfinn
Harsh Soni
 
funditpresFINAL
Victoria Muldowney
 
Ad

Similar to Mysql clone-tables (20)

PPTX
Database
marwa_ma
 
PPTX
MySQL Essential Training
HudaRaghibKadhim
 
PPTX
Creating database using sql commands
Belle Wx
 
PPTX
Sql tables
arwa wshyar
 
DOCX
database-querry-student-note
Leerpiny Makouach
 
PPT
mysqlHiep.ppt
webhostingguy
 
PPT
MySQL Database System Hiep Dinh
webhostingguy
 
PDF
Mysql cheatsheet
Adolfo Nasol
 
PDF
Sql wksht-2
Mukesh Tekwani
 
PPTX
DBMS - Presentationhgfhfhfghfghfhfgh.pptx
SajidHossainKhan1
 
PPTX
MYSql manage db
Ahmed Farag
 
PPT
MySql slides (ppt)
webhostingguy
 
DOCX
DBMS LAB M.docx
SuhaniSinha9
 
PPTX
Using Mysql.pptx
StephenEfange3
 
PDF
Sql subquery
Vivek Singh
 
PDF
Mysql Datadictionary
rootuser
 
PDF
Copy Of Mysql Datadictionary
Golak Sarangi
 
PPT
MySQL
Gouthaman V
 
PDF
Use sqlite
Jesus Diaz Gonzalez
 
PPTX
Oraclesql
Priya Goyal
 
Database
marwa_ma
 
MySQL Essential Training
HudaRaghibKadhim
 
Creating database using sql commands
Belle Wx
 
Sql tables
arwa wshyar
 
database-querry-student-note
Leerpiny Makouach
 
mysqlHiep.ppt
webhostingguy
 
MySQL Database System Hiep Dinh
webhostingguy
 
Mysql cheatsheet
Adolfo Nasol
 
Sql wksht-2
Mukesh Tekwani
 
DBMS - Presentationhgfhfhfghfghfhfgh.pptx
SajidHossainKhan1
 
MYSql manage db
Ahmed Farag
 
MySql slides (ppt)
webhostingguy
 
DBMS LAB M.docx
SuhaniSinha9
 
Using Mysql.pptx
StephenEfange3
 
Sql subquery
Vivek Singh
 
Mysql Datadictionary
rootuser
 
Copy Of Mysql Datadictionary
Golak Sarangi
 
Oraclesql
Priya Goyal
 
Ad

Recently uploaded (20)

PPTX
sajflsajfljsdfljslfjslfsdfas;fdsfksadfjlsdflkjslgfs;lfjlsajfl;sajfasfd.pptx
theknightme
 
PPTX
PE introd.pptxfrgfgfdgfdgfgrtretrt44t444
nepmithibai2024
 
PPTX
PM200.pptxghjgfhjghjghjghjghjghjghjghjghjghj
breadpaan921
 
PPTX
ONLINE BIRTH CERTIFICATE APPLICATION SYSYTEM PPT.pptx
ShyamasreeDutta
 
PPTX
一比一原版(LaTech毕业证)路易斯安那理工大学毕业证如何办理
Taqyea
 
PDF
Apple_Environmental_Progress_Report_2025.pdf
yiukwong
 
PDF
The-Hidden-Dangers-of-Skipping-Penetration-Testing.pdf.pdf
naksh4thra
 
PPTX
Presentation3gsgsgsgsdfgadgsfgfgsfgagsfgsfgzfdgsdgs.pptx
SUB03
 
PPT
Computer Securityyyyyyyy - Chapter 1.ppt
SolomonSB
 
PPTX
Cost_of_Quality_Presentation_Software_Engineering.pptx
farispalayi
 
PDF
DevOps Design for different deployment options
henrymails
 
PPTX
Orchestrating things in Angular application
Peter Abraham
 
PDF
Build Fast, Scale Faster: Milvus vs. Zilliz Cloud for Production-Ready AI
Zilliz
 
PPTX
英国假毕业证诺森比亚大学成绩单GPA修改UNN学生卡网上可查学历成绩单
Taqyea
 
PPTX
原版西班牙莱昂大学毕业证(León毕业证书)如何办理
Taqyea
 
PPTX
INTEGRATION OF ICT IN LEARNING AND INCORPORATIING TECHNOLOGY
kvshardwork1235
 
PPTX
unit 2_2 copy right fdrgfdgfai and sm.pptx
nepmithibai2024
 
PPT
Agilent Optoelectronic Solutions for Mobile Application
andreashenniger2
 
PPTX
Research Design - Report on seminar in thesis writing. PPTX
arvielobos1
 
PPTX
一比一原版(SUNY-Albany毕业证)纽约州立大学奥尔巴尼分校毕业证如何办理
Taqyea
 
sajflsajfljsdfljslfjslfsdfas;fdsfksadfjlsdflkjslgfs;lfjlsajfl;sajfasfd.pptx
theknightme
 
PE introd.pptxfrgfgfdgfdgfgrtretrt44t444
nepmithibai2024
 
PM200.pptxghjgfhjghjghjghjghjghjghjghjghjghj
breadpaan921
 
ONLINE BIRTH CERTIFICATE APPLICATION SYSYTEM PPT.pptx
ShyamasreeDutta
 
一比一原版(LaTech毕业证)路易斯安那理工大学毕业证如何办理
Taqyea
 
Apple_Environmental_Progress_Report_2025.pdf
yiukwong
 
The-Hidden-Dangers-of-Skipping-Penetration-Testing.pdf.pdf
naksh4thra
 
Presentation3gsgsgsgsdfgadgsfgfgsfgagsfgsfgzfdgsdgs.pptx
SUB03
 
Computer Securityyyyyyyy - Chapter 1.ppt
SolomonSB
 
Cost_of_Quality_Presentation_Software_Engineering.pptx
farispalayi
 
DevOps Design for different deployment options
henrymails
 
Orchestrating things in Angular application
Peter Abraham
 
Build Fast, Scale Faster: Milvus vs. Zilliz Cloud for Production-Ready AI
Zilliz
 
英国假毕业证诺森比亚大学成绩单GPA修改UNN学生卡网上可查学历成绩单
Taqyea
 
原版西班牙莱昂大学毕业证(León毕业证书)如何办理
Taqyea
 
INTEGRATION OF ICT IN LEARNING AND INCORPORATIING TECHNOLOGY
kvshardwork1235
 
unit 2_2 copy right fdrgfdgfai and sm.pptx
nepmithibai2024
 
Agilent Optoelectronic Solutions for Mobile Application
andreashenniger2
 
Research Design - Report on seminar in thesis writing. PPTX
arvielobos1
 
一比一原版(SUNY-Albany毕业证)纽约州立大学奥尔巴尼分校毕业证如何办理
Taqyea
 

Mysql clone-tables

  • 1. http://www.tutorialspoint.com/mysql/mysql-clone-tables.htm Copyright © tutorialspoint.com MYSQL CLONE TABLESMYSQL CLONE TABLES There may be a situation when 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: 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. Example: Try out the following example to create a clone table for tutorials_tbl. Step 1: Get complete structure about table. mysql> SHOW CREATE TABLE tutorials_tbl G; *************************** 1. row *************************** Table: tutorials_tbl Create Table: CREATE TABLE `tutorials_tbl` ( `tutorial_id` int(11) NOT NULL auto_increment, `tutorial_title` varchar(100) NOT NULL default '', `tutorial_author` varchar(40) NOT NULL default '', `submission_date` date default NULL, PRIMARY KEY (`tutorial_id`), UNIQUE KEY `AUTHOR_INDEX` (`tutorial_author`) ) TYPE=MyISAM 1 row in set (0.00 sec) ERROR: No query specified Step 2: Rename this table and create another table. mysql> CREATE TABLE `clone_tbl` ( -> `tutorial_id` int(11) NOT NULL auto_increment, -> `tutorial_title` varchar(100) NOT NULL default '', -> `tutorial_author` varchar(40) NOT NULL default '', -> `submission_date` date default NULL, -> PRIMARY KEY (`tutorial_id`), -> UNIQUE KEY `AUTHOR_INDEX` (`tutorial_author`) -> ) TYPE=MyISAM; Query OK, 0 rows affected (1.80 sec) Step 3: After executing step 2, you will create a clone table in your database. If you want to copy data from old table then you can do it by using INSERT INTO... SELECT statement. mysql> INSERT INTO clone_tbl (tutorial_id, -> tutorial_title,
  • 2. -> tutorial_author, -> submission_date) -> SELECT tutorial_id,tutorial_title, -> tutorial_author,submission_date, -> FROM tutorials_tbl; Query OK, 3 rows affected (0.07 sec) Records: 3 Duplicates: 0 Warnings: 0 Finally, you will have exact clone table as you wanted to have.