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