Hive表的基本操作(0923)


一、Databases

create database test;
create database test location '/temp/data';
create database if not exists test; 
select current_database();  // 查看当前数据库
use test;  // 切换数据库
create table test.tb1(id int,name string,age int);
insert into tb1 values(1,'tom',12) ; // 向表中插入数据
drop database test; // 删除空db
drop database test cascade;  // 级联删除test数据库,db中的表也删除
drop database if exists test cascade;
alter database test set owner user steven; 
set hive.cli.print.header=true; // hive sehll中设置显示表头
exit ;  // 退出hive shell

二、Tables;

show tables; 
show tables '*sam*'; 
show tables '*sam|lily*' ; 
show table extended like 'o*'; 
desc  table_name;
show create table table_name; 
show columns in table_name; 
alter table old_table rename to new_table;  // 表重命名
alter table student add columns(columnName type);   // 添加列
alter table student change old_column new_column type;  // 修改列
alter table student replace columns(id int,name string,age int);  // 替换列,也可以删除指定列
truncate table student;  // 删除表中所有的数据
drop table tablename;  // 删除表
// 启用/禁用表
alter table stu enable NO_DROP; //不允许删除
alter table stu disable NO_DROP;//允许删除  
// 导出表结构+数据到hdfs,数据保存在/temp/oo/data目录下,元数据保存在/temp/oo/_metadata文件中:
export table work to "/temp/oo";
export table employee_partition partition (year=2014, month=11) to '/temp/output'; 
// 数据导入
import table empolyee_imported from '/temp/oo'; 
import table employee_partitioned_imported from '/temp/output’;
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容