Mysql查询复制表的结构以创建另一个表

时间:2022-09-16 10:04:50

Looking for help in creating a Mysql query to copy the structure of an existing table to create another table.

寻求帮助创建一个Mysql查询来复制现有表的结构以创建另一个表。

4 个解决方案

#1


29  

To create a table as in an exact replica of another table:

要在另一个表的精确副本中创建表:

CREATE TABLE `new_table_name` LIKE `old_table_name`;

#2


14  

If you want to also copy the contents of the table you can do:

如果您还想复制表格的内容,您可以这样做:

CREATE TABLE `new_table_name` LIKE `old_table_name`;
INSERT INTO `new_table_name` SELECT * FROM `old_table_name`;

#3


6  

If you want to copy the table structure including its keys, then you should use:

如果要复制包含其键的表结构,则应使用:

CREATE TABLE `new_table_name` LIKE `old_table_name`;

To copy the whole table

复制整个表格

CREATE TABLE `new_table_name` SELECT * FROM `old_table_name`;

It will create the table and insert all the data from the old table but without bringing the keys from the old table. So you will need to set the keys for the new table.

它将创建表并插入旧表中的所有数据,但不从旧表中提取键。因此,您需要设置新表的键。

#4


0  

MySQL query to copy the structure of a table to create another table structure without data another way is...

MySQL查询复制表的结构,以另一种方式创建另一个没有数据的表结构是...

CREATE TABLE `table_name_new` select * from `table_name_old` limit 0;

#1


29  

To create a table as in an exact replica of another table:

要在另一个表的精确副本中创建表:

CREATE TABLE `new_table_name` LIKE `old_table_name`;

#2


14  

If you want to also copy the contents of the table you can do:

如果您还想复制表格的内容,您可以这样做:

CREATE TABLE `new_table_name` LIKE `old_table_name`;
INSERT INTO `new_table_name` SELECT * FROM `old_table_name`;

#3


6  

If you want to copy the table structure including its keys, then you should use:

如果要复制包含其键的表结构,则应使用:

CREATE TABLE `new_table_name` LIKE `old_table_name`;

To copy the whole table

复制整个表格

CREATE TABLE `new_table_name` SELECT * FROM `old_table_name`;

It will create the table and insert all the data from the old table but without bringing the keys from the old table. So you will need to set the keys for the new table.

它将创建表并插入旧表中的所有数据,但不从旧表中提取键。因此,您需要设置新表的键。

#4


0  

MySQL query to copy the structure of a table to create another table structure without data another way is...

MySQL查询复制表的结构,以另一种方式创建另一个没有数据的表结构是...

CREATE TABLE `table_name_new` select * from `table_name_old` limit 0;