MySQL Mysql查询复制一个表的结构创建另一个表
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3004876/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Mysql query to copy the structure of a table to create another table
提问by Hari kanna
Looking for help in creating a Mysql query to copy the structure of an existing table to create another table.
在创建 Mysql 查询以复制现有表的结构以创建另一个表方面寻求帮助。
回答by Hammerite
To create a table as in an exact replica of another table:
要在另一个表的精确副本中创建表:
CREATE TABLE `new_table_name` LIKE `old_table_name`;
回答by Monty
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`;
回答by Kamal Kumar
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.
它将创建表并插入旧表中的所有数据,但不会从旧表中引入键。因此,您需要为新表设置键。
回答by krishnaisdinesh
Its old thread but if someone needed. If you want create query that will create exactly copy of existing table.
它的旧线程,但如果有人需要。如果您想创建查询来创建现有表的完全副本。
show create table <existing table name>
回答by Sonpal singh Sengar
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;
回答by Aa.mbi
also you can use this:
你也可以使用这个:
CREATE TABLE 'new_table_name' SELECT * FROM 'pattern_table' where 1=0;