当前位置:网站首页>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
}

边栏推荐
- The performance of major mainstream programming languages is PK, and the results are unexpected
- .Net之延迟队列
- Leetcode 1200 minimum absolute difference [sort] The Path of leetcode for heroding
- Force button brush question 01 (reverse linked list + sliding window +lru cache mechanism)
- Exploration and practice of eventbridge in the field of SaaS enterprise integration
- 关于FPGA底层资源的细节问题
- Leetcode 1200 minimum absolute difference [sort] the way of leetcode in heroding
- 现代控制理论入门+理解
- 大神详解开源 BUFF 增益攻略丨直播
- LeetCode 1200 最小絕對差[排序] HERODING的LeetCode之路
猜你喜欢

Ali was laid off employees, looking for a job n day, headhunters came bad news

Ffmpeg Visual Studio development (IV): audio decoding

They are all talking about Devops. Do you really understand it?

leecode学习笔记-约瑟夫问题

UFO:微软学者提出视觉语言表征学习的统一Transformer,在多个多模态任务上达到SOTA性能!...

03-存储系统

Summary of common problems in development

Kubernets Pod 存在 Finalizers 一直处于 Terminating 状态

Techsmith Camtasia Studio 2022.0.2屏幕录制软件

Comment configurer un accord
随机推荐
hexadecimal
Redis 發布和訂閱
Preliminary exploration of flask: WSGI
Redis publier et s'abonner
mysql 联合主键_Mysql 创建联合主键[通俗易懂]
[Dalian University of technology] information sharing of postgraduate entrance examination and re examination
On the implementation plan of MySQL explain
进制乱炖
深度学习 神经网络的优化方法
重排数组
Intelligent customer service track: Netease Qiyu and Weier technology play different ways
PLC Analog input analog conversion FC s_ ITR (CoDeSys platform)
Go zero micro service practical series (IX. ultimate optimization of seckill performance)
Openresty current limiting
LVGL 8.2 LED
LVGL 8.2 Menu
UFO:微软学者提出视觉语言表征学习的统一Transformer,在多个多模态任务上达到SOTA性能!...
【大连理工大学】考研初试复试资料分享
Redis publish and subscribe
Guitar Pro 8win10最新版吉他学习 / 打谱 / 创作
