各种数据库的DDL语句汇总

数据库

Data Definition Language (DDL) is a standard for commands that define the different structures in a database. DDL statements create, modify, and remove database objects such as tables, indexes, and users. Common DDL statements are CREATE, ALTER, and DROP.

DDL语言全面数据定义语言(Data Define Language),是用于描述数据库中要存储的现实世界实体的语言。

主要的DDL动词:

CREATE(创建)、DROP(删除)、ALTER(修改)

TRUNCATE(截断)、RENAME(重命名)

Hive

创建语句

-- use database
create table database.table 
(
 `user_id` STRING COMMENT '用户id',
 `app_open_cnt` BIGINT COMMENT 'APP启动次数'
)
PARTITIONED BY (`dt` STRING COMMENT '日期,yyyy-MM-dd格式')
ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t' ;

增加列(单列)

alter table database.table add column gender string comment '用户性别'; 

增加列(多列)

alter table database.table add columns (
    gender string comment '用户性别',
    os string comment '用户终端'
);

更改列信息

alter table database.table change column gender is_gender boolean comment '是否男性'

PostgreSQL

创建语句

-- use database
create table database.table 
(
 `user_id` VARCHAR(200) NOT NULL,
 `app_open_cnt` BIGINT
);

comment on column table.user_id is '用户id';
comment on column table.app_open_cnt is 'APP启动次数';

作者:Qingyun
                
comments powered by Disqus