DDL
语法
create table table_1(
column_1 type constraint,
...
);
create table table_1(
column_1 type,
...
[constraint name] constraint(column_1,...)
)
create table table_1 as subquery;
drop table table_1;
alter table table_1 add|drop|modify (
column_1 type constraint,
...
);
alter table table_1 add [constraint name] primary key(column_1,...);
alter table table_1 drop primary key;
数据类型
整型
类型 |
大小 |
tinyint |
1 字节 |
smallint |
2 字节 |
mediumint |
3 字节 |
int或integer |
4 字节 |
bigint |
8 字节 |
浮点型
类型 |
大小 |
float |
4 字节 |
double |
8 字节 |
定点数
类型 |
大小 |
decimal |
不定 decimal(length, precision) |
日期
类型 |
大小 |
范围 |
格式 |
date |
3 字节 |
1000-01-01/9999-12-31 |
YYYY-MM-DD |
time |
3 字节 |
'-838:59:59'/'838:59:59' |
HH:MM:SS |
year |
1 字节 |
1901/2155 |
YYYY |
datetime |
8 字节 |
1000-01-01 00:00:00/9999-12-31 23:59:59 |
YYYY-MM-DD HH:MM:SS |
timestamp |
4 字节 |
1970-01-01 00:00:00/2038 结束时间是第 2147483647 秒,北京时间 2038-1-19 11:14:07,格林尼治时间 2038年1月19日 凌晨 03:14:07 |
YYYYMMDD HHMMSS |
字符
类型 |
大小 |
char |
不定 char(length) |
varchar |
不定 varchar(max_length) |
text |
65,535 字节 |
极大数据
类型 |
大小 |
blob |
65,535 字节 |
clob |
65,535 字节 |
约束
约束 |
关键字 |
含义 |
非空约束 |
not null |
不能为null |
默认约束 |
default |
未传入值,则采用默认值 |
唯一约束 |
unique |
不能重复,但是可以为null |
主键约束 |
primary key |
既不能重复,也不能为null auto_increment自然增长,Oracle不支持 |
外键约束 |
foreign key(t1_column_1) references table_2(t2_column_1) |
参照外键字段数据信息,参考字段必须唯一,外键值可以为null |
检查约束 |
check |
mysql不支持,oracle支持 |
Comments NOTHING