MySQL Guide: Creating a New Table from an Existing One
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 from an existing one in MySQL is a straightforward process that significantly streamlines tasks such as backing up data, archiving, or setting up new environments. This method not only saves time but also ensures consistency across databases, making it a valuable tool for developers and database administrators. Given its efficiency and consistency benefits, let’s explore the steps involved in creating a new table from an existing one in MySQL.
To only copy the structure of an existing table into a new one, execute the following SQL command:
CREATE TABLE new_table LIKE original_table;
This command creates a new table, new_table, mirroring the column definitions, indexes, and table properties of original_table, but without any of the data.
To create a new table that includes both the structure and data of an existing table, use this command:
CREATE TABLE new_table AS SELECT * FROM original_table;
Executing this command results in a new table, new_table, populated with all the data from original_table. It’s important to note that while this includes the data and basic structure, it does not include complex attributes like indexes and foreign keys.
You might want to customize which data or columns to copy into the new table. Achieve this by specifying the desired columns and any conditions for the data:
CREATE TABLE new_table AS SELECT column1, column2 FROM original_table WHERE condition;
Adjust column1, column2, and condition to match the specific columns and data criteria you need. This customization provides the flexibility to create tailored tables for various purposes.
If you need to replicate specific properties such as indexes or default values, you’ll have to manually define these in the CREATE TABLE command or apply them after creation with ALTER TABLE commands.
By using these commands, you can efficiently create new tables based on existing ones while maintaining control over the structure and content. Ensure to review the new table thoroughly to confirm it aligns with your requirements.
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.