hive中alter table的用法詳解

2021-07-28 06:08:59 字數 2259 閱讀 3556

alter table 語句

2011-07-22 11:02

alter table 語句用於在已有的表中新增、修改或刪除列。

1 . alter table table_name  add column_name datatype

2.  alter table table_name  drop column  column_name

3. alter table table_name   alter column column_name  datatype

sql alter table 例項

表 "persons" 中新增乙個名為 "birthday" 的新列

alter table persons add birthday date

刪除 "person" 表中的 "birthday" 列:

alter table person drop column birthday

1,alter table table_name drop (欄位1,欄位2,欄位3);

2,alter table table1 drop column a,b

增加乙個列:alter table 表名 add(列名 資料型別);

alter table emp add (weight number(38,0));

修改乙個列的資料型別(一般限於修改長度,修改為乙個不同型別時有諸多限制):

alter table 表名 modify(列名 資料型別);

alter table emp modify(weight number(3,0) not null);

給列改名:

alter table 表名 rename column 當前列名 to 新列名;

如:alter table emp rename column weight to weight_new;

刪除乙個列:

alter table 表名 drop column 列名;

如:alter table emp drop column weight_new;

將乙個表改名:

alter table 當前表名 rename to 新錶名;

如:alter table bouns rename to bonus_new

alter table語句用於修改已經存在的表的設計。

語法:alter table table add    column field type[(size)] [not null] [constraint index]

alter table table add    constraint multifieldindex

alter table table drop column field

alter table table drop constraint indexname

說明:table引數用於指定要修改的表的名稱。

add column為sql的保留字,使用它將向表中新增字段。

add constraint為sql的保留字,使用它將向表中新增索引。

drop column為sql的保留字,使用它將向表中刪除字段。

drop constraint為sql的保留字,使用它將向表中刪除索引。

field指定要新增或刪除的字段的名稱。 

type引數指定新建欄位的資料型別。

size引數用於指定文字或二進位製字段的長度。

indexname引數指定要刪除的多重字段索引的名稱。

因為需要修改乙個已存在的表的不允許為null的列改為可為null,網上查到的 

alter table table1 alter column [name] varchar(60) null; 

不適用於oracle,oracle應該使用如下形式: 

alter table tablename modify columnname columntype null; 

tablename:表名 

columnname:欄位名 

columntype:字段型別 

頂 0

踩0

使用sh -x除錯shell指令碼

sql中的left outer join,inner join,right outer join用法詳解

我的同類文章

hive(29)

加快alter table 操作速度

理論上,mysql可以跳過建立新錶的 步驟.列的預設值實際上存在表的.frm檔案中,所以可以直接修改這個檔案而不需要改動表本身。然而mysql還沒有採用這種優化的方法,所有的modify column操作都將導致表重建.這就是為什麼上圖直接使用modify column 有那麼多行受影響和需要那麼久...

MySQL 常見ALTER TABLE 操作

修改表的儲存引擎 show table status like tb 001 g alter table tb 001 type myisam 檢視表中列屬性 show columns from tb 001 修改表名 rename table tb 001 to tb 002 增加主鍵 alter...

mysql 常見ALTER TABLE操作

刪除列 alter table table name drop col name 增加列 單列 alter table table name add col name col type comment 增加列 多列 alter table table name add col name col ty...