How to Copy SQL Table Structure and Data
There are multiple ways to copy table structure and data to a new table, and here is one of them:
- Use the CREATE TABLE and INSERT INTO statements to replicate the table structure and data.
-- 复制表结构
CREATE TABLE new_table LIKE original_table;
-- 复制数据
INSERT INTO new_table SELECT * FROM original_table;
In the example above, a new table called “new_table” is created using the CREATE TABLE statement, with the same structure as the original table “original_table”. The data from the original table is then inserted into the new table using the INSERT INTO statement.
Please note that this method is only applicable to MySQL databases, other databases may require different syntax.