MySQL复制表结构和数据

mysql复制表有两种方式,create table ascreate table like,这二者仍是有差异,须要根据不一样的使用场景去选择
一、create table as,能够复制表结构,但不能复制索引;能够在复制表结构的同时复制数据
复制表结构mysql

create TABLE new_table as select * from old_table where 1=0;

复制表结构和数据sql

create table new_table as select * from old_table;

二、create table like,能够复制表结构和索引
复制表结构
create table new_table like old_table;segmentfault



欢迎订阅「K叔区块链」 - 专一于区块链技术学习

博客地址: http://www.jouypub.com
简书主页: https://www.jianshu.com/u/756c9c8ae984
segmentfault主页: https://segmentfault.com/blog/jouypub
腾讯云主页: https://cloud.tencent.com/developer/column/72548
相关文章
相关标签/搜索