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

Spss syntax
Spss syntaxSpss syntax
Spss syntax
rohit vishwakarma
 
Oracle: PLSQL Introduction
Oracle: PLSQL IntroductionOracle: PLSQL Introduction
Oracle: PLSQL Introduction
DataminingTools Inc
 
Oracle views
Oracle viewsOracle views
Oracle views
Balqees Al.Mubarak
 
Lab2 ddl commands
Lab2 ddl commandsLab2 ddl commands
Lab2 ddl commands
Balqees Al.Mubarak
 
SQL select clause
SQL select clauseSQL select clause
SQL select clause
arpit bhadoriya
 
Cursors in MySQL
Cursors in MySQL Cursors in MySQL
Cursors in MySQL
Tharindu Weerasinghe
 
Sql server ___________session_16(views)
Sql server  ___________session_16(views)Sql server  ___________session_16(views)
Sql server ___________session_16(views)
Ehtisham Ali
 
View & index in SQL
View & index in SQLView & index in SQL
View & index in SQL
Swapnali Pawar
 
Oracle training in hyderabad
Oracle training in hyderabadOracle training in hyderabad
Oracle training in hyderabad
Kelly Technologies
 
Oracle: DML
Oracle: DMLOracle: DML
Oracle: DML
DataminingTools Inc
 
Trigger and cursor program using sql
Trigger and cursor program using sqlTrigger and cursor program using sql
Trigger and cursor program using sqlSushil Mishra
 
Prabu's sql quries
Prabu's sql quries Prabu's sql quries
Prabu's sql quries Prabu Cse
 
My sql Syntax
My sql SyntaxMy sql Syntax
My sql SyntaxReka
 

What's hot (20)

Spss syntax
Spss syntaxSpss syntax
Spss syntax
 
Oracle: PLSQL Introduction
Oracle: PLSQL IntroductionOracle: PLSQL Introduction
Oracle: PLSQL Introduction
 
Les10
Les10Les10
Les10
 
Oracle views
Oracle viewsOracle views
Oracle views
 
Sql
SqlSql
Sql
 
Lab2 ddl commands
Lab2 ddl commandsLab2 ddl commands
Lab2 ddl commands
 
Views and functions
Views and functionsViews and functions
Views and functions
 
SQL select clause
SQL select clauseSQL select clause
SQL select clause
 
Cursors in MySQL
Cursors in MySQL Cursors in MySQL
Cursors in MySQL
 
Sql server ___________session_16(views)
Sql server  ___________session_16(views)Sql server  ___________session_16(views)
Sql server ___________session_16(views)
 
View & index in SQL
View & index in SQLView & index in SQL
View & index in SQL
 
Oracle training in hyderabad
Oracle training in hyderabadOracle training in hyderabad
Oracle training in hyderabad
 
SQL Views
SQL ViewsSQL Views
SQL Views
 
Les09
Les09Les09
Les09
 
Oracle: DML
Oracle: DMLOracle: DML
Oracle: DML
 
Les02
Les02Les02
Les02
 
Trigger and cursor program using sql
Trigger and cursor program using sqlTrigger and cursor program using sql
Trigger and cursor program using sql
 
Prabu's sql quries
Prabu's sql quries Prabu's sql quries
Prabu's sql quries
 
My sql Syntax
My sql SyntaxMy sql Syntax
My sql Syntax
 
4 trigger
4  trigger4  trigger
4 trigger
 

Viewers also liked

Grooming standards
Grooming standardsGrooming standards
Grooming standards
Dr. Sunil Kumar
 
Presentation ECN
Presentation ECNPresentation ECN
Presentation ECN
Nadia Ayala
 
P&G
P&GP&G
Каждому "свой " вид спорта - работа ученицы 5 «А» класса МБОУ Школы № 70 Си...
 Каждому "свой " вид спорта -  работа ученицы 5 «А» класса МБОУ Школы № 70 Си... Каждому "свой " вид спорта -  работа ученицы 5 «А» класса МБОУ Школы № 70 Си...
Каждому "свой " вид спорта - работа ученицы 5 «А» класса МБОУ Школы № 70 Си...
School70_Samara
 
Official Campus Eye Slide Deck
Official Campus Eye Slide DeckOfficial Campus Eye Slide Deck
Official Campus Eye Slide Deck
Garrett Foley
 
CONOTEL - Congresso Nacional de Hotéis
CONOTEL - Congresso Nacional de HotéisCONOTEL - Congresso Nacional de Hotéis
CONOTEL - Congresso Nacional de Hotéis
TEKNERGIA
 
Bo si do bo --- http://xuongmayquanaokn.com/
Bo si do bo --- http://xuongmayquanaokn.com/Bo si do bo --- http://xuongmayquanaokn.com/
Bo si do bo --- http://xuongmayquanaokn.com/
xưởng may KN
 
BlueBRIDGE: Cloud infrastructure serving aquafarms and supporting models
BlueBRIDGE: Cloud infrastructure serving aquafarms and supporting modelsBlueBRIDGE: Cloud infrastructure serving aquafarms and supporting models
BlueBRIDGE: Cloud infrastructure serving aquafarms and supporting models
Blue BRIDGE
 
Virtual Research Environments supporting tailor-made data management service...
Virtual Research Environments supporting tailor-made data management service...Virtual Research Environments supporting tailor-made data management service...
Virtual Research Environments supporting tailor-made data management service...
Blue BRIDGE
 
MED101 Introduction to Amazon CloudFront - AWS re: Invent 2012
MED101 Introduction to Amazon CloudFront - AWS re: Invent 2012MED101 Introduction to Amazon CloudFront - AWS re: Invent 2012
MED101 Introduction to Amazon CloudFront - AWS re: Invent 2012
Amazon Web Services
 
Grooming at workplace
Grooming at workplaceGrooming at workplace
Grooming at workplace
Ravi Kumar
 
Personal Grooming
Personal GroomingPersonal Grooming
Personal Grooming
MMMTS
 
Frankfinn Grooming Presentation ...
Frankfinn Grooming Presentation ...Frankfinn Grooming Presentation ...
Frankfinn Grooming Presentation ...
Syed Shabbir Hussain
 
Frankfinn Grooming Presentation
Frankfinn Grooming PresentationFrankfinn Grooming Presentation
Frankfinn Grooming Presentationryan dias
 
Grooming PPT Frankfinn
Grooming PPT FrankfinnGrooming PPT Frankfinn
Grooming PPT Frankfinn
Harsh Soni
 

Viewers also liked (20)

Grooming standards
Grooming standardsGrooming standards
Grooming standards
 
Grooming accesories
Grooming accesoriesGrooming accesories
Grooming accesories
 
Presentation ECN
Presentation ECNPresentation ECN
Presentation ECN
 
RESUME
RESUMERESUME
RESUME
 
P&G
P&GP&G
P&G
 
Каждому "свой " вид спорта - работа ученицы 5 «А» класса МБОУ Школы № 70 Си...
 Каждому "свой " вид спорта -  работа ученицы 5 «А» класса МБОУ Школы № 70 Си... Каждому "свой " вид спорта -  работа ученицы 5 «А» класса МБОУ Школы № 70 Си...
Каждому "свой " вид спорта - работа ученицы 5 «А» класса МБОУ Школы № 70 Си...
 
Official Campus Eye Slide Deck
Official Campus Eye Slide DeckOfficial Campus Eye Slide Deck
Official Campus Eye Slide Deck
 
CONOTEL - Congresso Nacional de Hotéis
CONOTEL - Congresso Nacional de HotéisCONOTEL - Congresso Nacional de Hotéis
CONOTEL - Congresso Nacional de Hotéis
 
Bo si do bo --- http://xuongmayquanaokn.com/
Bo si do bo --- http://xuongmayquanaokn.com/Bo si do bo --- http://xuongmayquanaokn.com/
Bo si do bo --- http://xuongmayquanaokn.com/
 
BlueBRIDGE: Cloud infrastructure serving aquafarms and supporting models
BlueBRIDGE: Cloud infrastructure serving aquafarms and supporting modelsBlueBRIDGE: Cloud infrastructure serving aquafarms and supporting models
BlueBRIDGE: Cloud infrastructure serving aquafarms and supporting models
 
Virtual Research Environments supporting tailor-made data management service...
Virtual Research Environments supporting tailor-made data management service...Virtual Research Environments supporting tailor-made data management service...
Virtual Research Environments supporting tailor-made data management service...
 
MED101 Introduction to Amazon CloudFront - AWS re: Invent 2012
MED101 Introduction to Amazon CloudFront - AWS re: Invent 2012MED101 Introduction to Amazon CloudFront - AWS re: Invent 2012
MED101 Introduction to Amazon CloudFront - AWS re: Invent 2012
 
Grooming
GroomingGrooming
Grooming
 
Gubendran Lakshmanan
Gubendran LakshmananGubendran Lakshmanan
Gubendran Lakshmanan
 
GROOMING ASSIGNMENT
GROOMING ASSIGNMENTGROOMING ASSIGNMENT
GROOMING ASSIGNMENT
 
Grooming at workplace
Grooming at workplaceGrooming at workplace
Grooming at workplace
 
Personal Grooming
Personal GroomingPersonal Grooming
Personal Grooming
 
Frankfinn Grooming Presentation ...
Frankfinn Grooming Presentation ...Frankfinn Grooming Presentation ...
Frankfinn Grooming Presentation ...
 
Frankfinn Grooming Presentation
Frankfinn Grooming PresentationFrankfinn Grooming Presentation
Frankfinn Grooming Presentation
 
Grooming PPT Frankfinn
Grooming PPT FrankfinnGrooming PPT Frankfinn
Grooming PPT Frankfinn
 

Similar to Mysql clone-tables

Database
DatabaseDatabase
Database
marwa_ma
 
MySQL Essential Training
MySQL Essential TrainingMySQL Essential Training
MySQL Essential Training
HudaRaghibKadhim
 
Creating database using sql commands
Creating database using sql commandsCreating database using sql commands
Creating database using sql commandsBelle Wx
 
Sql tables
Sql tablesSql tables
Sql tables
arwa wshyar
 
database-querry-student-note
database-querry-student-notedatabase-querry-student-note
database-querry-student-noteLeerpiny Makouach
 
MySQL Database System Hiep Dinh
MySQL Database System Hiep DinhMySQL Database System Hiep Dinh
MySQL Database System Hiep Dinhwebhostingguy
 
MYSql manage db
MYSql manage dbMYSql manage db
MYSql manage db
Ahmed Farag
 
DBMS LAB M.docx
DBMS LAB M.docxDBMS LAB M.docx
DBMS LAB M.docx
SuhaniSinha9
 
Using Mysql.pptx
Using Mysql.pptxUsing Mysql.pptx
Using Mysql.pptx
StephenEfange3
 
Copy Of Mysql Datadictionary
Copy Of Mysql DatadictionaryCopy Of Mysql Datadictionary
Copy Of Mysql DatadictionaryGolak Sarangi
 
Mysql Datadictionary
Mysql DatadictionaryMysql Datadictionary
Mysql Datadictionaryrootuser
 
MySQL
MySQLMySQL
Use sqlite
Use sqliteUse sqlite
Oraclesql
OraclesqlOraclesql
Oraclesql
Priya Goyal
 
chapter 8 SQL.ppt
chapter 8 SQL.pptchapter 8 SQL.ppt
chapter 8 SQL.ppt
YitbarekMurche
 

Similar to Mysql clone-tables (20)

Database
DatabaseDatabase
Database
 
MySQL Essential Training
MySQL Essential TrainingMySQL Essential Training
MySQL Essential Training
 
Creating database using sql commands
Creating database using sql commandsCreating database using sql commands
Creating database using sql commands
 
Sql tables
Sql tablesSql tables
Sql tables
 
database-querry-student-note
database-querry-student-notedatabase-querry-student-note
database-querry-student-note
 
MySQL Database System Hiep Dinh
MySQL Database System Hiep DinhMySQL Database System Hiep Dinh
MySQL Database System Hiep Dinh
 
mysqlHiep.ppt
mysqlHiep.pptmysqlHiep.ppt
mysqlHiep.ppt
 
Mysql cheatsheet
Mysql cheatsheetMysql cheatsheet
Mysql cheatsheet
 
Sql wksht-2
Sql wksht-2Sql wksht-2
Sql wksht-2
 
MYSql manage db
MYSql manage dbMYSql manage db
MYSql manage db
 
MySql slides (ppt)
MySql slides (ppt)MySql slides (ppt)
MySql slides (ppt)
 
DBMS LAB M.docx
DBMS LAB M.docxDBMS LAB M.docx
DBMS LAB M.docx
 
Using Mysql.pptx
Using Mysql.pptxUsing Mysql.pptx
Using Mysql.pptx
 
Sql subquery
Sql subquerySql subquery
Sql subquery
 
Copy Of Mysql Datadictionary
Copy Of Mysql DatadictionaryCopy Of Mysql Datadictionary
Copy Of Mysql Datadictionary
 
Mysql Datadictionary
Mysql DatadictionaryMysql Datadictionary
Mysql Datadictionary
 
MySQL
MySQLMySQL
MySQL
 
Use sqlite
Use sqliteUse sqlite
Use sqlite
 
Oraclesql
OraclesqlOraclesql
Oraclesql
 
chapter 8 SQL.ppt
chapter 8 SQL.pptchapter 8 SQL.ppt
chapter 8 SQL.ppt
 

Recently uploaded

The+Prospects+of+E-Commerce+in+China.pptx
The+Prospects+of+E-Commerce+in+China.pptxThe+Prospects+of+E-Commerce+in+China.pptx
The+Prospects+of+E-Commerce+in+China.pptx
laozhuseo02
 
How to Use Contact Form 7 Like a Pro.pptx
How to Use Contact Form 7 Like a Pro.pptxHow to Use Contact Form 7 Like a Pro.pptx
How to Use Contact Form 7 Like a Pro.pptx
Gal Baras
 
急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样
急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样
急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样
3ipehhoa
 
This 7-second Brain Wave Ritual Attracts Money To You.!
This 7-second Brain Wave Ritual Attracts Money To You.!This 7-second Brain Wave Ritual Attracts Money To You.!
This 7-second Brain Wave Ritual Attracts Money To You.!
nirahealhty
 
BASIC C++ lecture NOTE C++ lecture 3.pptx
BASIC C++ lecture NOTE C++ lecture 3.pptxBASIC C++ lecture NOTE C++ lecture 3.pptx
BASIC C++ lecture NOTE C++ lecture 3.pptx
natyesu
 
History+of+E-commerce+Development+in+China-www.cfye-commerce.shop
History+of+E-commerce+Development+in+China-www.cfye-commerce.shopHistory+of+E-commerce+Development+in+China-www.cfye-commerce.shop
History+of+E-commerce+Development+in+China-www.cfye-commerce.shop
laozhuseo02
 
guildmasters guide to ravnica Dungeons & Dragons 5...
guildmasters guide to ravnica Dungeons & Dragons 5...guildmasters guide to ravnica Dungeons & Dragons 5...
guildmasters guide to ravnica Dungeons & Dragons 5...
Rogerio Filho
 
1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样
1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样
1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样
3ipehhoa
 
Output determination SAP S4 HANA SAP SD CC
Output determination SAP S4 HANA SAP SD CCOutput determination SAP S4 HANA SAP SD CC
Output determination SAP S4 HANA SAP SD CC
ShahulHameed54211
 
test test test test testtest test testtest test testtest test testtest test ...
test test  test test testtest test testtest test testtest test testtest test ...test test  test test testtest test testtest test testtest test testtest test ...
test test test test testtest test testtest test testtest test testtest test ...
Arif0071
 
1.Wireless Communication System_Wireless communication is a broad term that i...
1.Wireless Communication System_Wireless communication is a broad term that i...1.Wireless Communication System_Wireless communication is a broad term that i...
1.Wireless Communication System_Wireless communication is a broad term that i...
JeyaPerumal1
 
原版仿制(uob毕业证书)英国伯明翰大学毕业证本科学历证书原版一模一样
原版仿制(uob毕业证书)英国伯明翰大学毕业证本科学历证书原版一模一样原版仿制(uob毕业证书)英国伯明翰大学毕业证本科学历证书原版一模一样
原版仿制(uob毕业证书)英国伯明翰大学毕业证本科学历证书原版一模一样
3ipehhoa
 
Living-in-IT-era-Module-7-Imaging-and-Design-for-Social-Impact.pptx
Living-in-IT-era-Module-7-Imaging-and-Design-for-Social-Impact.pptxLiving-in-IT-era-Module-7-Imaging-and-Design-for-Social-Impact.pptx
Living-in-IT-era-Module-7-Imaging-and-Design-for-Social-Impact.pptx
TristanJasperRamos
 
ER(Entity Relationship) Diagram for online shopping - TAE
ER(Entity Relationship) Diagram for online shopping - TAEER(Entity Relationship) Diagram for online shopping - TAE
ER(Entity Relationship) Diagram for online shopping - TAE
Himani415946
 
Latest trends in computer networking.pptx
Latest trends in computer networking.pptxLatest trends in computer networking.pptx
Latest trends in computer networking.pptx
JungkooksNonexistent
 
Multi-cluster Kubernetes Networking- Patterns, Projects and Guidelines
Multi-cluster Kubernetes Networking- Patterns, Projects and GuidelinesMulti-cluster Kubernetes Networking- Patterns, Projects and Guidelines
Multi-cluster Kubernetes Networking- Patterns, Projects and Guidelines
Sanjeev Rampal
 

Recently uploaded (16)

The+Prospects+of+E-Commerce+in+China.pptx
The+Prospects+of+E-Commerce+in+China.pptxThe+Prospects+of+E-Commerce+in+China.pptx
The+Prospects+of+E-Commerce+in+China.pptx
 
How to Use Contact Form 7 Like a Pro.pptx
How to Use Contact Form 7 Like a Pro.pptxHow to Use Contact Form 7 Like a Pro.pptx
How to Use Contact Form 7 Like a Pro.pptx
 
急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样
急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样
急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样
 
This 7-second Brain Wave Ritual Attracts Money To You.!
This 7-second Brain Wave Ritual Attracts Money To You.!This 7-second Brain Wave Ritual Attracts Money To You.!
This 7-second Brain Wave Ritual Attracts Money To You.!
 
BASIC C++ lecture NOTE C++ lecture 3.pptx
BASIC C++ lecture NOTE C++ lecture 3.pptxBASIC C++ lecture NOTE C++ lecture 3.pptx
BASIC C++ lecture NOTE C++ lecture 3.pptx
 
History+of+E-commerce+Development+in+China-www.cfye-commerce.shop
History+of+E-commerce+Development+in+China-www.cfye-commerce.shopHistory+of+E-commerce+Development+in+China-www.cfye-commerce.shop
History+of+E-commerce+Development+in+China-www.cfye-commerce.shop
 
guildmasters guide to ravnica Dungeons & Dragons 5...
guildmasters guide to ravnica Dungeons & Dragons 5...guildmasters guide to ravnica Dungeons & Dragons 5...
guildmasters guide to ravnica Dungeons & Dragons 5...
 
1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样
1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样
1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样
 
Output determination SAP S4 HANA SAP SD CC
Output determination SAP S4 HANA SAP SD CCOutput determination SAP S4 HANA SAP SD CC
Output determination SAP S4 HANA SAP SD CC
 
test test test test testtest test testtest test testtest test testtest test ...
test test  test test testtest test testtest test testtest test testtest test ...test test  test test testtest test testtest test testtest test testtest test ...
test test test test testtest test testtest test testtest test testtest test ...
 
1.Wireless Communication System_Wireless communication is a broad term that i...
1.Wireless Communication System_Wireless communication is a broad term that i...1.Wireless Communication System_Wireless communication is a broad term that i...
1.Wireless Communication System_Wireless communication is a broad term that i...
 
原版仿制(uob毕业证书)英国伯明翰大学毕业证本科学历证书原版一模一样
原版仿制(uob毕业证书)英国伯明翰大学毕业证本科学历证书原版一模一样原版仿制(uob毕业证书)英国伯明翰大学毕业证本科学历证书原版一模一样
原版仿制(uob毕业证书)英国伯明翰大学毕业证本科学历证书原版一模一样
 
Living-in-IT-era-Module-7-Imaging-and-Design-for-Social-Impact.pptx
Living-in-IT-era-Module-7-Imaging-and-Design-for-Social-Impact.pptxLiving-in-IT-era-Module-7-Imaging-and-Design-for-Social-Impact.pptx
Living-in-IT-era-Module-7-Imaging-and-Design-for-Social-Impact.pptx
 
ER(Entity Relationship) Diagram for online shopping - TAE
ER(Entity Relationship) Diagram for online shopping - TAEER(Entity Relationship) Diagram for online shopping - TAE
ER(Entity Relationship) Diagram for online shopping - TAE
 
Latest trends in computer networking.pptx
Latest trends in computer networking.pptxLatest trends in computer networking.pptx
Latest trends in computer networking.pptx
 
Multi-cluster Kubernetes Networking- Patterns, Projects and Guidelines
Multi-cluster Kubernetes Networking- Patterns, Projects and GuidelinesMulti-cluster Kubernetes Networking- Patterns, Projects and Guidelines
Multi-cluster Kubernetes Networking- Patterns, Projects and Guidelines
 

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.