Hive學習之更改表的屬性
1、修改表名
alter table table_name rename to new_table_name;
例1:alter table ruoze_emp rename to emp;
2、修改列名
alter table tablename change column column_orign column_new int(修改後列的屬性) comment 'column_name'
after severity;//可以把該列放到指定列的後面,或者使用‘first’放到第一位
將表tablename中的列column_orign修改成column_new,同時指定修改後的列名稱的屬性,comment是這個列的註釋
例1:alter table emp change column age uage double comment 'column age' after id;
3、增加列
alter table tablename add columns(column1 string comment 'xxxx',column2 long comment 'yyyy')
例1:alter table emp add columns(age int);
4、替換表
ALTER TABLE table_name [PARTITION partition_spec] ADD|REPLACE COLUMNS (col_name data_type [COMMENT col_comment], ...) [CASCADE|RESTRICT] -- (Note: Hive 1.1.0 and later)
例1:ALTER TABLE emp REPLACE COLUMNS (age int, uage int);
5、檢視錶的屬性
desc formatted tablename;
6、修改表的屬性
(1)alter table table_name set tblproperties('property_name'='new_value');
將table_name表中的comment屬性值修改成'new_value';
(2)alter table emp set serdeproperties ("field.delim"="\t");
將表table_name中的欄位分割符修改成'\t',注意,這是在表沒有分割槽的情況下
例1:create table emp(id int,uname string)row format delimited fields terminated by '#' lines terminated by '\n' stored as textfile;
alter table emp set serdeproperties('field.delim'='\t');這條語句將t8表中的欄位分隔符'#'修改成'\t';
例2:create table emp(id int,uname string) partitioned by(dt=string) row foramt delimited fields terminated by '\n' stored as textfile;
alter table emp partition(dt='20180108') set serdeproperties('field.delim=\t');
(3)alter table table_name[partition] set location 'path'
alter table emp set TBLPROPERTIES('EXTERNAL'='TRUE');//內部錶轉化成外部表
alter table emp set TBLPROPERTIES('EXTERNAL'='FALSE');//外部錶轉成內部表
注意:由於emp預設是內表,所以在刪除表emp時,它的資料包括檔案目錄全部被刪除,為了防止這種情況發生,可以將表emp修改成外表,
透過語句:alter table emp set tblproperties('EXTERNAL'='TRUE');同樣也可以將外部表修改為內部表,
可以透過語句:alter table city set tblproperties('EXTERNAL'='FALSE');
(4)其他修改表屬性的命令:
alter table properties; alter serde properties;
alter table/partition file format;
alter table storage properties;
alter table rename partition;
alter table set location;
詳細說明可以參考:Hive官網,在官網中找:wiki LanguageManual DDL()來查詢詳細介紹
若澤大資料交流群:671914634
alter table table_name rename to new_table_name;
例1:alter table ruoze_emp rename to emp;
2、修改列名
alter table tablename change column column_orign column_new int(修改後列的屬性) comment 'column_name'
after severity;//可以把該列放到指定列的後面,或者使用‘first’放到第一位
將表tablename中的列column_orign修改成column_new,同時指定修改後的列名稱的屬性,comment是這個列的註釋
例1:alter table emp change column age uage double comment 'column age' after id;
3、增加列
alter table tablename add columns(column1 string comment 'xxxx',column2 long comment 'yyyy')
例1:alter table emp add columns(age int);
4、替換表
ALTER TABLE table_name [PARTITION partition_spec] ADD|REPLACE COLUMNS (col_name data_type [COMMENT col_comment], ...) [CASCADE|RESTRICT] -- (Note: Hive 1.1.0 and later)
例1:ALTER TABLE emp REPLACE COLUMNS (age int, uage int);
5、檢視錶的屬性
desc formatted tablename;
6、修改表的屬性
(1)alter table table_name set tblproperties('property_name'='new_value');
將table_name表中的comment屬性值修改成'new_value';
(2)alter table emp set serdeproperties ("field.delim"="\t");
將表table_name中的欄位分割符修改成'\t',注意,這是在表沒有分割槽的情況下
例1:create table emp(id int,uname string)row format delimited fields terminated by '#' lines terminated by '\n' stored as textfile;
alter table emp set serdeproperties('field.delim'='\t');這條語句將t8表中的欄位分隔符'#'修改成'\t';
例2:create table emp(id int,uname string) partitioned by(dt=string) row foramt delimited fields terminated by '\n' stored as textfile;
alter table emp partition(dt='20180108') set serdeproperties('field.delim=\t');
(3)alter table table_name[partition] set location 'path'
alter table emp set TBLPROPERTIES('EXTERNAL'='TRUE');//內部錶轉化成外部表
alter table emp set TBLPROPERTIES('EXTERNAL'='FALSE');//外部錶轉成內部表
注意:由於emp預設是內表,所以在刪除表emp時,它的資料包括檔案目錄全部被刪除,為了防止這種情況發生,可以將表emp修改成外表,
透過語句:alter table emp set tblproperties('EXTERNAL'='TRUE');同樣也可以將外部表修改為內部表,
可以透過語句:alter table city set tblproperties('EXTERNAL'='FALSE');
(4)其他修改表屬性的命令:
alter table properties; alter serde properties;
alter table/partition file format;
alter table storage properties;
alter table rename partition;
alter table set location;
詳細說明可以參考:Hive官網,在官網中找:wiki LanguageManual DDL()來查詢詳細介紹
若澤大資料交流群:671914634
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/31511218/viewspace-2149885/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Hive學習之常見屬性配置Hive
- Hive學習之Hive的安裝Hive
- hive學習筆記之四:分割槽表Hive筆記
- HIVE學習之(三)Hive
- Hive學習之基本操作Hive
- Salesforce LWC學習(三十四) 如何更改標準元件的相關屬性資訊Salesforce元件
- Hive學習之JDBC訪問HiveJDBC
- CALayer學習--contentsCenter屬性
- win10怎麼更改網路屬性_要如何更改網路屬性windows10Win10Windows
- win10怎樣更改連線屬性_win10怎麼更改網路屬性Win10
- PostgreSQL/Lightdb 更改列屬性語法SQL
- MySQL學習之全域性鎖和表鎖MySql
- Hive學習之常用互動命令Hive
- Hive學習之型別轉化Hive型別
- hive學習筆記之八:SqoopHive筆記OOP
- hive學習筆記之十一:UDTFHive筆記
- CMake 屬性之全域性屬性
- 學習Rust:派生derive屬性Rust
- Matlab_GUI學習筆記(三)——常用物件的屬性之FigureMatlabGUI筆記物件
- VueJs中動態更改svg的相關屬性VueJSSVG
- Hive學習Hive
- 好程式設計師大資料學習路線之hive表的查詢程式設計師大資料Hive
- hive學習筆記之五:分桶Hive筆記
- CMake 屬性之目錄屬性
- CMake 屬性之目標屬性
- 鄧洋前端學習——Flex佈局之flex-basis屬性前端Flex
- hive學習之四:hive檔案格式以及壓縮編碼Hive
- hive學習筆記之三:內部表和外部表Hive筆記
- 前端學習-vue影片學習007-標籤的ref屬性前端Vue
- PostgreSQL:表的儲存屬性SQL
- JavaScript中的物件學習筆記(屬性操作)JavaScript物件筆記
- WPF依賴屬性的正確學習方法
- 學習CSS的background屬性及其取值(實踐)CSS
- 線性表學習1
- 資料結構基礎學習之線性表資料結構
- hive學習筆記之九:基礎UDFHive筆記
- hive學習筆記之六:HiveQL基礎Hive筆記
- React學習手記2-屬性校驗和預設屬性React
- 零基礎學習 Python 之細說類屬性 & 例項Python