在MySQL中创建与另一个表匹配的表? [英] Create table in MySQL that matches another table?

查看:266
本文介绍了在MySQL中创建与另一个表匹配的表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am using MySQL. I have a table called EMP, and now I need create one more table (EMP_TWO) with same schema, same columns, and same constraints. How can I do this?

推荐答案

要基于其他表结构/约束创建新表,请使用:

To create a new table based on another tables structure / constraints use :

CREATE TABLE new_table LIKE old_table;     

要在需要时跨数据复制,请使用

To copy the data across, if required, use

INSERT INTO new_table SELECT * FROM old_table;  

创建表文档

当心有关LIKE选项的注意事项:

Beware of the notes on the LIKE option :

使用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:

创建表new_table类似于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仅适用于基表,不适用于视图.

LIKE works only for base tables, not for views.

创建表...像不保留任何数据目录或索引 为原始表指定的DIRECTORY表选项,或者 任何外键定义.

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中创建与另一个表匹配的表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆