mysql - 在 MySQL 中创建与另一个表匹配的表?

标签 mysql

我正在使用 MySQL。我有一个名为 EMP 的表,现在我需要再创建一个具有相同架构、相同列和相同约束的表 (EMP_TWO)。我该怎么做?

最佳答案

要基于另一个表结构/约束创建新表,请使用:

CREATE TABLE new_table LIKE old_table;     

若需要复制数据,请使用

INSERT INTO new_table SELECT * FROM old_table;  

Create table docs

注意 LIKE 选项的注意事项:

Use LIKE to create an empty table based on the definition of another table, including any column attributes and indexes defined in the original table:

CREATE TABLE new_table LIKE original_table; The copy is created using the same version of the table storage format as the original table. The SELECT privilege is required on the original table.

LIKE works only for base tables, not for views.

CREATE TABLE ... LIKE does not preserve any DATA DIRECTORY or INDEX DIRECTORY table options that were specified for the original table, or any foreign key definitions.

关于mysql - 在 MySQL 中创建与另一个表匹配的表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8761358/

相关文章:

php - MySQL 全文搜索 - 数值和 ft_min_word_len 的解决方法

mysql - 如何在 View mysql中重复多个父id的所有子id

mysql - 需要mysql更新select查询进行优化

mysql - 如何在VB.NET中等待MySQL更新?

javascript - 从 javascript 内部调用 PHP 函数?

php - 如何使用 PHP 在 MySQL 数据库表中查找一行并仅插入一个值?

mysql - 无法创建/写入文件 '/tmp/#sql_17f0_0.MYD'(错误代码 : 17)

php - PDO:使用增量键在 MySQL 中插入数组

php - 在 PHP 中释放内存

java - 我想在 Java 应用程序和 Xampp 之间进行连接