how to duplicate table in mysql code example

Example 1: mysql copy table with new name

CREATE TABLE IF NOT EXISTS new_table LIKE existing_table;

INSERT new_table
SELECT * FROM existing_table;

Example 2: how to duplicate table in mysql

CREATE table `duplicat` LIKE `orginal`;
INSERT `duplicat` SELECT * FROM `orginal`;

Example 3: duplicate row mysql

# Duplicate rows or row
INSERT INTO table (col1, col2, col3)
SELECT col1, col2, col3 FROM table
WHERE something...;

Example 4: duplicate row mysql

# Duplicate row and change values in the duplicated row
INSERT INTO table (col1, col2, col3)
# manually insert data to the duplicated row
SELECT "new value", "new value", "new value" FROM table
WHERE something...;

Tags:

Misc Example