一、创建表
语法:
create [temporary] [external] table [if not exists] [db_name.] table_name
[(col_name data_type [comment col_comment], ...)]
[comment table_comment]
[row format row_format]
[stored as file_format]
例子:
create table if not exists person (
id int,
name string
)
comment 'human table'
row format delimited
fields terminated by '\t'
lines terminated by '\n'
stored as textfile;
二、查看表的结构
语法;
desc[ribe] table_name;
例子:
describe person;
三、修改表
语法:
alter table name rename to new_name
alter table name add columns (col_spec[, col_spec ...])
alter table name change column_name new_name new_type
alter table name replace columns (col_spec[, col_spec ...])
修改表名:
alter table person rename to human;
加列:
alter table human add columns (age int);
删除列:
四、删除表
语法:
drop table [if exists] table_name;
例子:
drop table human;
五、数据插入、查询与删除
插入:
insert into human values(1,'pan',13);
查询:
select * from human;
删除:
truncate table table_name;
-- 清空表,第二种方式
insert overwrite table table_name select * from table_name where 1=0;