MySQL FAQs
FAQs Categories
Client Server Commands
Database Structure
Table Types or Storage Engines
Indexes
SQL Statements
Table Joins
Funtions and Operators
Tricky Select Queries
Speed Up Queries
Data Back Up
General Questions
Errors
N.M.P.L. Company www.NearMePayday.Loan || 3-month (90 days)
Powered by MySQL
 
Home / Data Back Up / Question No: 178

How to create duplicate table in MySQL?

I want to create a duplicate table of my already created table in the same database. Can you explain, how to create duplicate table of an existing table in MySQL?

Answer No: 178

MySQL provides many methods to create duplicate table with its data or without its data. The following is a simple example to create a duplicate table alongwith data of the original table:

CREATE TABLE new_table_name SELECT * FROM old_table_name; 

The above query will create a table named 'new_table_name' like table 'old_table_name' and entire data from old table will be copied to new table. An important point to note is that this query will not create column attributes and indexes as defined in the original table. However, if you also want to have such attributes, this can be done with another easy way. Take a look at the following queries:

CREATE TABLE new_table_name LIKE old_table_name;

This query will create a copy of the original table with all its constraints and attributes. Now, you need to insert entire data from original table to new one table so run the following query:

INSERT INTO new_table_name SELECT * FROM `old_table_name`;

Related MySQL FAQs to the Above FAQ

How-can-I-restore-MySQL-database How can I restore MySQL database?

About FAQs: Recently Added FAQs

About MySQL FAQs: Site Map | Bookmark Us

Useful Links: Wikipedia.org | Oracle.com | w3schools.com | www.php.net | Github.com

© 2021  www.mysqlfaqs.net
All rights reserved.