修改表结构
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
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