当前位置:网站首页>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
}
边栏推荐
- Ffprobe common commands
- LeetCode 1200 最小绝对差[排序] HERODING的LeetCode之路
- [local differential privacy and random response code implementation] differential privacy code implementation series (13)
- Analysis of nearly 100 million dollars stolen and horizon cross chain bridge attacked
- I plan to teach myself some programming and want to work as a part-time programmer. I want to ask which programmer has a simple part-time platform list and doesn't investigate the degree of the receiv
- Optimization method of deep learning neural network
- C1 certification learning notes 3 -- Web Foundation
- 文本挖掘工具的介绍[通俗易懂]
- Flutter reports an error no mediaquery widget ancestor found
- Korean AI team plagiarizes shock academia! One tutor with 51 students, or plagiarism recidivist
猜你喜欢
暑期复习,一定要避免踩这些坑!
Halo effect - who says that those with light on their heads are heroes
Luo Gu - some interesting questions
LVGL 8.2 Line
[local differential privacy and random response code implementation] differential privacy code implementation series (13)
31年前的Beyond演唱会,是如何超清修复的?
深度学习 网络正则化
Korean AI team plagiarizes shock academia! One tutor with 51 students, or plagiarism recidivist
Summer Review, we must avoid stepping on these holes!
Weibo and Huya advance into interest communities: different paths for peers
随机推荐
How to match chords
Ffmpeg Visual Studio development (IV): audio decoding
Deep learning network regularization
各大主流编程语言性能PK,结果出乎意料
When synchronized encounters this thing, there is a big hole, pay attention!
Enter the width!
31年前的Beyond演唱会,是如何超清修复的?
文本挖掘工具的介绍[通俗易懂]
Redis的4种缓存模式分享
近一亿美元失窃,Horizon跨链桥被攻击事件分析
LeetCode 1200 最小絕對差[排序] HERODING的LeetCode之路
Deep learning 7 transformer series instance segmentation mask2former
Intelligent customer service track: Netease Qiyu and Weier technology play different ways
[local differential privacy and random response code implementation] differential privacy code implementation series (13)
mysql 联合主键_Mysql 创建联合主键[通俗易懂]
Memory management summary
UFO:微软学者提出视觉语言表征学习的统一Transformer,在多个多模态任务上达到SOTA性能!...
5G电视难成竞争优势,视频资源成中国广电最后武器
左右对齐!
Halcon knowledge: NCC_ Model template matching