基本数据类型
1整型:
1 tinyint 2 int 3bigint
create table t1 (x int(5) unsigned zerofill)
int 后面的数字指的是显示宽度,并不是存储限制
查看 sql模式 show variables like '%mode%';
浮点型
float double decimal
create table t2(x float(5,3)) 代表总共5位,整数两位,小数3位
精度 float double decimal 越来越高
字符类型
char 定长
varchar 变长
create table t3(s char(4))字符单位个数限制,不足的用空格填充
create table t4(s char(4))超出报错,有几个存几个
select char_length(x) from t3;查看字符长度
char 缺点:浪费空间
有点:存取速度快
日期类型:
data :1990-09-20
time:10:30:20
datetime:1990-09-20 10:30:20
year:2000
枚举与集合类型
枚举 enum 多选一
集合 set 多选多
create table t1 (s enum('play','read'))
create table t2 (s set('play','read'))
insert into t2 ('play,read')
insert into t1 ('play')