MySQL Tutorial: Using CREATE TABLE LIKE for Easy Cloning
Robert Cooper
Robert Cooper Senior Engineer at Basedash
· January 31, 2025
Robert Cooper
Robert Cooper Senior Engineer at Basedash
· January 31, 2025
Creating a new table in MySQL that mirrors the structure of an existing table is both straightforward and efficient using the CREATE TABLE LIKE statement. This exploration equips you with the knowledge and tools to streamline your database management, enhance efficiency, and more.
CREATE TABLE LIKE in MySQL?The CREATE TABLE LIKE statement allows you to clone the structure of an existing table in MySQL. This clones column names, data types, indexes, and other attributes, while excluding the data from the original table.
Here’s the basic syntax:
CREATE TABLE new_table LIKE existing_table;
In this syntax, replace new_table with the name of the table you want to create, and existing_table with the name of the table whose structure you wish to clone.
Let’s say you have an employees table and want to create a employees_backup table with the same structure. Execute the following command:
CREATE TABLE employees_backup LIKE employees;
Executing this command creates a new employees_backup table with identical column definitions, indexes, and table properties as the employees table but omits the data.
CREATE TABLE LIKE does not copy foreign key constraints. Manually add these to your new table if necessary.Employing this method effectively sets up test environments or backs up table structures efficiently, bypassing the data copying overhead and maintaining development momentum.
Written by
Senior Engineer at Basedash
Robert Cooper is a senior engineer at Basedash who builds full-stack product systems across SQL data infrastructure, APIs, and frontend architecture. His work focuses on application performance, developer velocity, and reliable self-hosted workflows that make data operations easier for teams at scale.
Basedash lets you build charts, dashboards, and reports in seconds using all your data.