当前位置:网站首页>MySQL学习笔记——数据类型(数值类型)
MySQL学习笔记——数据类型(数值类型)
2022-07-04 14:04:00 【默萧756】
目录
一、数据类型精讲
1、MySQL中的数据类型
2、整数类型
2.1 类型介绍
示例:
8.0中类型后面会有(),例如tinyint(4),代表的是加上符号所占的数位,而-128到+127就是4位。如果使用无符号UNSIGNED,就是3。8.0以后不建议去指定宽度。
2.2 可选属性
1、不适用ZEROFILL时,指定和不指定显示宽度无所谓。使用ZEROFILL时,指定显示宽度为n,当insert的值不足n位,就用0填充,如果超过n位,就不用。
2、当使用ZEROFILL时,自动会添加UNSIGNED
2.3 使用场景
2.4 如何选择
3、浮点类型
3.1 类型介绍
3.2 数据精度说明
示例:
1、使用FLOAT和DOUBLE时,最好别加M和D。
2、在编程中,如果使用到浮点数,要特别注意误差问题,因为浮点数是不精准的,所以要尽量避免使用=来判断两个浮点数是否相等。在MySQL里面,有着更加精准的数据类型:DECIMAL;
4、定点数类型
4.1 类型介绍
使用DECIMAL时,一般加上M和D,不加的话,默认(10,0)。
4.2 浮点数VS定点数
浮点数相对于定点数的优点是长度一定的情况下,浮点类型取值范围大,但是不精确,适用于需要取值范围大,又可以容忍微小误差的科学计算场景(比如计算化学、分子建模、流动力学等)、
定点数类型取值范围相对较小,但是精准,没有误差,适用于对精度要求极高的场景(比如涉及金额计算的场景)
4.3 开发中的经验
5、位类型
CREATE TABLE test_bit1{
f1 BIT,f2BIT(5); //f1默认二进制数位是1,因此只能为0和1,f2数位是5,因此可以存0-31
}
边栏推荐
- 暑期复习,一定要避免踩这些坑!
- Partial modification - progressive development
- Graduation season - personal summary
- Openresty current limiting
- C1 certification learning notes 3 -- Web Foundation
- [Dalian University of technology] information sharing of postgraduate entrance examination and re examination
- Is BigDecimal safe to calculate the amount? Look at these five pits~~
- Programmers exposed that they took private jobs: they took more than 30 orders in 10 months, with a net income of 400000
- LVGL 8.2 Menu
- Usage of database functions "recommended collection"
猜你喜欢
Kubernets pod exists finalizers are always in terminating state
Quick introduction to automatic control principle + understanding
LVGL 8.2 Line
大神详解开源 BUFF 增益攻略丨直播
一篇文章搞懂Go语言中的Context
Deep learning network regularization
Luo Gu - some interesting questions
金额计算用 BigDecimal 就万无一失了?看看这五个坑吧~~
Intelligent customer service track: Netease Qiyu and Weier technology play different ways
韩国AI团队抄袭震动学界!1个导师带51个学生,还是抄袭惯犯
随机推荐
%f格式符
重排数组
小数,指数
Huawei cloud database DDS products are deeply enabled
谈SaaS下如何迅速部署应用软件
LeetCode 1200 最小絕對差[排序] HERODING的LeetCode之路
Quick introduction to automatic control principle + understanding
Yyds dry goods inventory # solve the real problem of famous enterprises: continuous maximum sum
Techsmith Camtasia Studio 2022.0.2屏幕录制软件
Redis哨兵模式实现一主二从三哨兵
宽度精度
[Dalian University of technology] information sharing of postgraduate entrance examination and re examination
一篇文章搞懂Go语言中的Context
找数字
Leecode learning notes - Joseph problem
CentOS 6.3 下 PHP编译安装JSON模块报错解决
【学习笔记】拟阵
Halo effect - who says that those with light on their heads are heroes
Halcon knowledge: NCC_ Model template matching
Flutter reports an error no mediaquery widget ancestor found