creat table page_view (
user_id bigint,view_time bigint,page_url string,referrer_url string,ip string comment 'creat table sql') partitioned by (dt string,country string);
注:comment後為注釋,用單引号區分。分區字段單列,dt和country為兩個分區,根據順序dt為一級分區,country為二級分區,MAXCOMPUTE支援的最大分區數為6個,表的最大列數為1200列。
creat table page_view_test like page_view;
注:like語句隻複制表的結構,schema相同,建立的表中沒有資料,也不複制原表的生命周期。
creat table page_view_url as select page_url,referrer_url from page view;
注:as語句隻複制表的資料,不完全複制表的結構,建立的表中沒有分區,也不複制原表的生命周期。
備注:Partitioned by指定表的分區字段,目前支援Tinyint、Smallint、 Int、 Bigint、Varchar和String類型。分區值不允許有雙位元組字元(如中文),必須是以英文字母a-z,A-Z開始後可跟字母數字,名稱的長度不超過128位元組。一張表最多允許60000個分區,單表的分區層次不能超過6級。注釋内容是長度不超過1024位元組的有效字元串。
desc page_view;
注:檢視表的資訊
desc extended page_view;
注:檢視外部表的資訊
drop table page_view;
注:删除表
drop table if exists page_view;
注:删除表,如果不指定if exists選項而表不存在,則傳回異常。若指定此選項,無論表是否存在,皆傳回成功。
alter table page_view rename to page_view_1;
注:修改表的名字
alter table page_view set comment 'new';
注:修改表的注釋
turncate table page_view;
注:清除非分區表中的資訊
turncate table page_view drop partition (dt='2011-12-17);
注:清除分區表中某個分區的資訊
creat table page_view (user_id bigint) lifecycle 100;
注:建立表并把表的生命周期設定為100天。
alter table page_view set lifecycle 50;
注:修改已經有的表格生命周期為50天。
alter table page_view add if not exists partition (dt='2015-1-1',region='shanghai');
注:增加分區,僅支援新增分區,不支援新增分區字段。如果未指定if not exists而同名的分區已存在,則出錯傳回。目前MaxCompute單表支援的分區數量上限為6萬。對于多級分區的表,如果想添加新的分區,必須指明全部的分區值。
alter table page_view drop if exists partiton (dt='2015-1-1',region='shanghai');
注:删除分區。如果分區不存在且未指定if exists,則報錯傳回。
alter table page_view add columns (id bigint,url string);
注:增加列
alter table page_view change column id rename to id_1;
注:修改列的名字
alter table page_view change column id comment 'change';
注:修改列的注釋
alter table page_view partition (dt='2013-01-01') rename to partition (dt='2013-01-02');
注:修改分區列的值,不支援修改分區列列名,隻能修改分區列對應的值。修改多級分區的一個或者多個分區值,多級分區的每一級的分區值都必須寫上。
creat view if not exists data_1;
注:建立視圖。建立視圖時,必須有對視圖所引用表的讀權限。視圖隻能包含一個有效的select語句。視圖可以引用其它視圖,但不能引用自己,也不能循環引用。不允許向視圖寫入資料,例如使用insert into或者insert overwrite操作視圖。當建好視圖後,如果視圖的引用表發生了變更,有可能導緻視圖無法通路,例如删除被引用表。您需要自己維護引用表及視圖之間的對應關系。如果沒有指定if not exists,在視圖已經存在時用create view會導緻異常。這種情況可以用create or replace view來重建視圖,重建後視圖本身的權限保持不變。
drop view if exists data_1;
注:删除視圖。
alter view data_1 rename to data_2;
注:修改視圖名稱。