Notes

MySQL - Duplicate tables

author: Paul Kim

categories: mysql

tags: mysql

Copy the data and structure, but not the indexes

CREATE TABLE new_table SELECT * FROM old_table;

Copy the table structure and indexes, but not the data

CREATE TABLE new_table LIKE old_table;

Copy both the data, table structure and indexes

CREATE TABLE new_table LIKE old_table;
INSERT new_table SELECT * FROM old_table;

Copy table from one database to another

CREATE TABLE destination_db.new_table LIKE source_db.old_table;

INSERT destination_db.new_table
SELECT
    *
FROM
    source_db.old_table;

ChromeEdgeFirefoxOpera

© 2021 paulkode.com. All rights reserved.