Copy MYSQL Table Structure and Import Specific Columns

This code will allow you to copy the table structure from an existing table into a new one and then copy data from specific columns

-- Step 1: Create the new table with the same structure as the existing table
CREATE TABLE NewTableName LIKE ExistingTableName;

-- Step 2: Insert data from the specified columns of the existing table into the new table
INSERT INTO NewTableName (Column1, Column2)
SELECT Column1, Colum2
FROM ExistingTableName;
Disclaimer: The code on this website is provided "as is" and comes with no warranty. The author of this website does not accept any responsibility for issues arising from the use of code on this website. Before making any significant changes, ensure you take a backup of all files and do not work directly on a live/production website without thoughly testing your changes first.

Leave a Reply

Your email address will not be published. Required fields are marked *