devxlogo

Create a Table from an Existing Table in MySQL

Create a Table from an Existing Table in MySQL

MySQL provides a command named LIKE that can be used in CREATE TABLE command. This is most useful when you want to create a new table along with the indexes of the source table.

CREATE TABLE new_table LIKE existing_table

The LIKE command will replicate the existing_table structure to the new_table along with the indexes as well.

Note: Foreign keys will not be copied.

devx-admin

Share the Post: