MySQL create table as与create table like对比
對于mysql的復制相同表結構方法,有create table as 和create table like 兩種,區別是什么呢?
????create table t2 as select * from t1 where 1=2 ; 或者 limit 0;
as創建出來的t2表(新表)缺少t1表(源表)的索引信息,只有表結構相同,沒有索引。
????create table t2 like t1 ;
like 創建出來的新表包含源表的完整表結構和索引信息
二者的用途:
????as用來創建相同表結構并復制源表數據
????like用來創建完整表結構和全部索引
————————————————
a、create table like方式會完整地克隆表結構,但不會插入數據,需要單獨使用insert into或load data方式加載數據
b、create table as??方式會部分克隆表結構,完整保留數據
c、create table as select .. where 1=0 會克隆部分表結構,但不克隆數據。
d、如果啟用了gtid,create table as方式不被支持。收到ERROR 1786 (HY000): CREATE TABLE ... SELECT is forbidden when @@GLOBAL.ENFORCE_GTID_CONSISTENCY = 1.
————————————————
?
總結
以上是生活随笔為你收集整理的MySQL create table as与create table like对比的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Oracle的AWR报告分析
- 下一篇: vscode for mac怎样关闭自动