当前位置:网站首页>数据类型与约束
数据类型与约束
2022-07-13 17:32:00 【Pony_18】
参考文章:菜鸟教程 https://www.runoob.com/mysql/mysql-data-types.html
- 为了更加准确的存储数据,保证数据的正确有效,需要合理的使用数据类型和约束来限制数据的存储。
MySQL中定义数据字段的类型对数据库的优化是非常重要的。
MySQL支持多种类型,大致可以分为三类:数值、日期/时间和字符串(字符)类型。
常用数据类型
- 整数:int,4个字节,32位,能代表的最大数为:2^32-1=4294967296,有符号范围(-2147483648 ~2147483647),无符号范围(0 ~ 4294967295)
- 双精度浮点数:double,8个字节
- 小数:decimal,如decimal(5,2)表示共存5位数,小数占2位,整数占3位
- 小整数:tinyint,1个字节
- 字符串:varchar,范围(0~65533),如varchar(3)表示最多存3个字符,一个中文或一个字母都占一个字符
- 日期时间: datetime,范围(1000-01-01 00:00:00 ~ 9999-12-31 23:59:59),如'2020-01-01 12:29:59'
约束
- 主键(primary key):物理上存储的顺序,代表一条记录的唯一标识,不能重复也不能为空。
- 非空(not null):此字段不允许填写空值
- 惟一(unique):此字段的值不允许重复
- 默认值(default):当不填写此值时会使用默认值,如果填写时以填写为准
- 外键(foreign key):维护两个表之间的关联关系
边栏推荐
- 系统总出故障怎么办,或许你该学学稳定性建设!
- Six diseases of distributed monomers
- Niobe 407 of kaihong Zhigu was officially incorporated into the code trunk of openharmony
- yandexbot ip 地址段
- Tensor是如何让你的内存/显存泄漏的
- 开鸿智谷 Niobe 407 正式并入OpenHarmony代码主干
- 分布式单体的六大病症
- Learning to Estimate 3D Hand Pose from Single RGB Image&amp笔记
- Flink CDC 在大健云仓的实践
- Solve the problem of unable to load authentication plugin 'caching' when idea2020 connects to MySQL 8_ sha2_ Password 'exception
猜你喜欢
随机推荐
mysql中all用法和any的用法和内连接和外连接,全外连接,联合查询,自连接
钱大妈基于 Flink 的实时风控实践
yandexbot ip 地址段
What if the system always breaks down? Maybe you should learn stability construction!
[underlying principle] what is a socket? Why is the network inseparable from socket?
[explore why string class is an immutable type: String class imitation]
Exploration and practice of integration of streaming and wholesale in jd.com
番茄定时调光台灯触摸芯片-DLT8T10S-杰力科创
分布式单体的六大病症
解决ssm项目上传图片后无法及时回显
Flink CDC + OceanBase 全增量一体化数据集成方案
注册实现。
Pointer storage array C
基于logisim的八位求补器的设计与实现
Centos7 network configuration and docker installation, MySQL image pulling and docker basic commands
rogerbot 爬虫介绍
Résoudre le problème de l'échec de l'écho en temps opportun après le téléchargement de l'image du projet SSM
Flink CDC + oceanbase full incremental integrated data integration scheme
Lombok @Data导致的hashCode的问题
数据操作—查询篇
![[untitled]](/img/d8/a367c26b51d9dbaf53bf4fe2a13917.png)








