如何使用键和表复制表格MySQL中保留的其他结构功能? [英] How to duplicate a table with keys & other structure features retained in MySQL?

查看:155
本文介绍了如何使用键和表复制表格MySQL中保留的其他结构功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用键和表复制表格其他结构特征保留?包括主键,外键和索引。

How to duplicate a table with keys & other structure features retained? including primary key, foreign keys, and indexes.

这可以通过单个MySQL查询完成吗?

Can this be done with a single MySQL query?

我正在使用create table newtable as select ...,但是这种方法可以使所有键和&索引丢失。

I'm using "create table newtable as select..." but this method makes all keys & indexes lost.

推荐答案

使用单个查询无法完成从另一个表复制表(带索引和结构)
您需要2个查询。

duplicating a table from another table (with indexing and structure)cannot be done with a single query you will need need 2 queries.

1)创建重复表。

CREATE TABLE Table2 LIKE Table1;

这将创建表格的精确副本。

This will create an exact copy of the table.

2)填写带有原始表值的Duplicate表。

2) Fill in the Duplicate table with values from original table.

INSERT INTO Table2 SELECT * from Table1;

将填写Table2以及表1

will fill Table2 with all the records fom Table1

这篇关于如何使用键和表复制表格MySQL中保留的其他结构功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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