gpt4 book ai didi

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

转载 作者:IT老高 更新时间:2023-10-28 12:52:54 31 4
gpt4 key购买 nike

我正在使用 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/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com