hive sql, myql ,oracle ,postgresql修改表结构总结

修改表结构
HIVE:

ALTER TABLE t_md_wecar_navi_month_user CHANGE all_week_active_user  all_month_active_user bigint

修改表字段类型
ALTER TABLE test_table CHANGE col1 col2 STRING COMMENT 'The datatype of col2 is STRING' AFTER col3
上面的语句将列名col1修改为col2,数据类型为STRING并添加注释,最后将这一列放在col3后面


增加表字段,和oracle一样
ALTER TABLE test_table add columns(col  STRING) 


mysql:
增加表字段 
ALTER TABLE test_table add colx  varchar(100); 
ALTER TABLE test_table add colxx  bigint(20); 


修改表字段:
    alter table student change name name varchar(20)not null default 'liming';//修改字段类型 default后边是

增加:alter table tablename add name type;
删除:alter table tablename drop name ;
修改:alter table tablename change oldname newname type ;
修改属性:alter table tablename change oldname oldname type ;
重命名字段:alter table tablename change oldname newname integer;

ORACLE:

--增加字段  
alter table luffy.student_test2 add (CDR_CONTENT      VARCHAR2(2000));  
alter table luffy.student_test2 add (COURSE_INST_ID      NUMBER(12));  
alter table luffy.student_test2 add ADDRESS VARCHAR2(40);  

--删除字段  
alter table luffy.student_test2 drop column CDR_CONTENT;  
alter table luffy.student_test2 drop column PROD_INST_ID;  
alter table luffy.student_test2 drop column ADDRESS ;  

--修改字段长度和类型  
alter table luffy.student_test2 modify(id number(7));--将字段长度改为7  
alter table luffy.student_test2 modify id number(20);--将字段长度改为20  

alter table luffy.student_test2 modify(id varchar2(8));--将字段类型由number改为varchar2,长度为8,(要更改类型,需要修改的列必须为空)  
alter table luffy.student_test2 modify id varchar2(20);--将字段类型由number改为varchar2,长度为20,(要更改类型,需要修改的列必须为空)  

--修改字段名称  
alter table luffy.student_test2 rename column id to stu_id;  
alter table luffy.student_test2 rename column stu_id to id;  


postgresql:
   向表中增加一个 varchar 列:
ALTER TABLE distributors ADD COLUMN address varchar(30);
 
从表中删除一个字段:
ALTER TABLE distributors DROP COLUMN address RESTRICT;
 
在一个操作中修改两个现有字段的类型:
ALTER TABLE distributors
ALTER COLUMN address TYPE varchar(80),
ALTER COLUMN name TYPE varchar(100);

   对现存字段改名:
ALTER TABLE distributors RENAME COLUMN address TO city;


7.查看表结构

查看表结构:desc formatted table_name;  
查看建表语句:show create table table_name;
查看表分区:show partitions table_name;
查看分区对应hdfs:desc formatted?table_name partition ();
计算分区数据量大小:show tablesize partitions table_name;
计算某个分区的文件总数:show rowcount extended table_name
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值