Mysql create table tb as select 和create table tb 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用來創建完整表結構和全部索引

所以 as select 子句一般適用於建表並複製源表數據的情況,like子句適用於只複製表結構的情況

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章