Hive的DDL+DML

1.DDL操作
(1)数据库DDL

a.查看所有数据库:show databases (like 模糊查询字符串);	
b.创建数据库:create database if not exists dbName;
c.删除数据库:drop database if exists dbName (cascade); cascade—数据库下有表时,加该字段可强制删除数据库
d.修改数据库:alter database dbName set dbproperties(修改的属性信息key=value格式)
e.查看数据库的描述:desc database (extended)dbName;  extended—加该字段查询更详细的信息
f.切换数据库:use dbName;

(2)表的DDL

a.查看所有表:show tables (直接跟模糊查询字段);
b.创建表:create table if not exists tabName(字段1 类型1,字段2 类型2,...);
c.复制表:create table1 like table; 只拷贝表结构
				 create table2 as select * from table; 拷贝表结构及数据
d.导入表:load data local inpath 路径 overwrite into table tabName; 导入本地路径到表
e.查看表结构:desc (extended,formatted) table; formatted查看详细的表结构(比extended清晰)
f.查看表的创建语句:show create table tabName;
g.修改表:alter table tabName1 rename to tabName2;
h.删除表:drop table if exists tabName;
i.清空表中所有数据:truncate table tabName;

猜你喜欢

转载自blog.csdn.net/chenyh_csdn/article/details/84036525