![903b852c7f40383078f2ad9dd7c38a12.png](https://img-blog.csdnimg.cn/img_convert/903b852c7f40383078f2ad9dd7c38a12.png)
点击这里关注"程序员Bob"
![09a9b3ccde2c04a3af20e43a6ad659b5.png](https://img-blog.csdnimg.cn/img_convert/09a9b3ccde2c04a3af20e43a6ad659b5.png)
![e5d94dea65380947f5018bcc578fde21.png](https://img-blog.csdnimg.cn/img_convert/e5d94dea65380947f5018bcc578fde21.png)
I am not afraid of tomorrow for I have seen yesterday and love today.我不害怕明天,因为我经历过昨天,又热爱今天。
![e470020f32ca40037882adfe30df4f4b.png](https://img-blog.csdnimg.cn/img_convert/e470020f32ca40037882adfe30df4f4b.png)
![8d0f8252fbc8e8a033658657706723ba.png](https://img-blog.csdnimg.cn/img_convert/8d0f8252fbc8e8a033658657706723ba.png)
![8d0f8252fbc8e8a033658657706723ba.png](https://img-blog.csdnimg.cn/img_convert/8d0f8252fbc8e8a033658657706723ba.png)
![8d0f8252fbc8e8a033658657706723ba.png](https://img-blog.csdnimg.cn/img_convert/8d0f8252fbc8e8a033658657706723ba.png)
![d1e20f5ba9f8ed10cd7d52cc152f9848.gif](https://img-blog.csdnimg.cn/img_convert/d1e20f5ba9f8ed10cd7d52cc152f9848.gif)
Tinyint(常用):使用一个字节存储表示的状态最多为256种(八个字节最大表示256个)
Smallint:使用2个字节存储,表示的状态最多为65536
mediumint:使用3个字节存储
int(常用):使用四个字节存储
Bigint:使用八个字节存储
-- 创建整形 create table my_int( int_1 tinyint, int_2 smallint, int_3 int, int_4 bigint )charset utf8;
创建一张整形表(如上):插入数据:只能插入范围内的整型
在表中插入相关数据:
-- 插入数据insert into my_int values (100,100,100,100); -- 有效数据insert into my_int values ('a','b','199','f'); -- 无效数据insert into my_int values (255,10000,100000,1000000); -- 错误:超出范围
分别执行如下:
在SQL中,数值类型全部都是默认为有符号,比如正负。
而有时候需要使用无符号数据限定,例如需要给数据类型进行限定(使用):int unsigned;- -无符号:
从0开始语句:alter table my_int add int_5 tinyint unsigned;
执行如下:alter table my_int add int_7 tinyint(2) zerofill;insert into my_int values (1,1,1,1,1,1,1);insert into my_int values (100,100,100,100,100,100,100);
执行如下:
float(单精度):占用4个字节存储数据,精度范围大概为7位左右
double(双精度):占用8个字节存储数据,精度范围大概为15位左右
相关语句:
-- 浮点数(10位在精度范围之外,6位在精度范围之内)create table my_float(f1 float,f2 float(10,2),f3 float(6,2))charset utf8;
执行如下:
-- 插入数据insert into my_float values (1234.10,1234.10,1234.10);-- 符合条件insert into my_float values (123456789,12345678.99,9999.99);-- 最大值insert into my_float values (3e38,3.01e7,1234.56); -- 科学计数法
上面是符合规范的,下面演示相关错误语句:
-- 超出长度的限制insert into my_float values (123456,1234.12345678,123.1234567); -- 小数部分可行,整数部分超出(不会报错)insert into my_float values (123456,1234.12,12345.12); -- 整数部分超出(会报错)
执行如下:
往期推荐:
洛谷 || 最厉害的学生
2020-10-18
![8c9ac8865cb91f8bfae1975236727c1a.png](https://img-blog.csdnimg.cn/img_convert/8c9ac8865cb91f8bfae1975236727c1a.png)
MySQL基础学习之大战数据操作
2020-10-17
![aa45ad11e00672092238758d1e186653.png](https://img-blog.csdnimg.cn/img_convert/aa45ad11e00672092238758d1e186653.png)
关于小编
2020-10-06
![780599a0f859e4e230e372b121b1715f.png](https://img-blog.csdnimg.cn/img_convert/780599a0f859e4e230e372b121b1715f.png)
为你,千千万万遍.
关注程序员Bob公众号,与你一起终生学习
![c9fe572f87319eac900b14eada00719a.png](https://img-blog.csdnimg.cn/img_convert/c9fe572f87319eac900b14eada00719a.png)