1. Create a table of three positions
The first
//员工表
create table if not exists default.emp(
empno int,
ename string,
job string,
mgr int,
hiredate string,
sal double,
comm double,
deptno int
)
row format delimited fields terminated by '\t';
//部门表
create table if not exists default.dept(
deptno int,
dname string,
loc string
)
row format delimited fields terminated by '\t';
The second
create table if not exists default.dept_ctas
as
select * from dept;
NOTE: This method copies the data structures and tables
The third
create table if not exists default.dept_like
like
default.dept;
Note: This method will only copy the structure of the table, the table does not copy data
2. insert data into the table
eg:
load data 【local】 inpath '/opt/datas/emp.txt' 【overwrite】 into table emp;
load data 【local】 inpath '/opt/datas/dept.txt' 【overwrite】 into table dept;
local参数
使用该参数表示本地文件系统
不使用是hdfs文件系统
overwrite参数
使用该参数表示覆盖原表中的数据
不使用追加到原表中
3.清除表的数据
truncate table dept_ctas;
4.修改表的名称
alter table dept_like rename to dept_like_rename;
5.删除表
drop table if exists dept_like_rename;
6.查看表详情
desc formatted default.dept;
7.查看当前数据库的表
show tables;
8.查看所有的数据库
show databases;