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
相關文章
相關標籤/搜索