5、数值类型

一 整形

 

1、无符号  unsigned

无符号:就是非负数,可以增加数据长度。只能用于整数

 

2、前导零  zerofill 本意:零填充

alter table class add status int(m);
alter table class add stat int(m) zerofill;//

m 的含义不是允许字段的长度,而是显示长度,在为字段设置 zerofill时有效。

例如:int(5) 值为123
正常:123
设置前导零后:00123

 

 

 

 

tinyint    范围:负128    到  127    unsigned  255

smallint 范围: 负3万2  到  3万2

int          范围:-21亿    到   21亿

 

二 浮点数

近似值:float 2的23次方 83886087

精确值:decimal 存钱用这个

alter table class add sal float(6,2); 参数1:数据总位数   参数2:小数点后面的位数

 

三 枚举类型 enum

enum不用再转换,tinyiny还需要再转换

alter table class add sex enum('男','女') default null;

insert into class (name,sex) values('李逵',2);

适合存储单选框类的数据:如性别等

 

四 多选框类型 set

alter table class add flag set('置顶','推荐','热门','加粗');

insert into class(name,flag)values('刘备','加粗,推荐');

查询方式:

select * from class where find_in_set('推荐',flag);//1 find_in_set查询

select * from class where flag like '%推荐%';//2 模糊查询

select * from class where flag = '推荐,加粗';//3 必须完全匹配

 

 

posted @ 2020-12-03 21:13  棉花糖88  阅读(138)  评论(0)    收藏  举报