当前位置:网站首页>MYSQL入门与进阶(六)
MYSQL入门与进阶(六)
2022-07-28 17:05:00 【小新爱编程】
目录
1、 约束
我们在创建数据库表的时候
CREATE TABLE 表名 (
列名 类型 [约束],
列名 类型 [约束]
)
2、约束分类
2.1、primary key
主键约束 当一列创建的时候 添加primary key 此时 这一列就添加了主键约束,这一列就称之为 主键列。例如
Create table student (
id int primary key
)
此时 id这一列就是添加了主键约束 ,这一列称之为 主键列。
当添加了 主键约束之后,此时这一列就有了非空(这一列必须有值)且唯一(这一列的每行的值不能重复)的限定。
疑问:能不能使用unique + not null代替primary key ?
不可以,因为 primary key 除了非空且唯一的限定之外 ,还有一个功能就是 主键索引的功能。
有兴趣的从二叉树开始研究(不需要会代码)
所以 我们数据库表都有一个 id列 设定成为主键约束
2.2、AUTO_INCREMENT(自增长)
2.3、DEFAULT(默认)
2.4、unique代表唯一约束。
唯一约束是指定table的列或列组合不能重复,保证数据的唯一性
2.5、not null为非空约束,
指定某一行的值不能为null。
3、SQL文件的导入和导出
导出:选中数据库–》右键—》转存储SQL --》保存
导入:
4、MYSQL数据类型
TINYINT 1 Bytes (-128,127) (0,255) 小整数值
SMALLINT 2 Bytes (-32 768,32 767) (0,65 535) 大整数值
MEDIUMINT 3 Bytes (-8 388 608,8 388 607) (0,16 777 215) 大整数值
INT或INTEGER 4 Bytes (-2 147 483 648,2 147 483 647) (0,4 294 967 295) 大整数值
BIGINT 8 Bytes (-9,223,372,036,854,775,808,9 223 372 036 854 775 807) (0,18 446 744 073 709 551 615) 极大整数值
FLOAT 4 Bytes (-3.402 823 466 E+38,-1.175 494 351 E-38),0,(1.175 494 351 E-38,3.402 823 466 351 E+38) 0,(1.175 494 351 E-38,3.402 823 466 E+38) 单精度浮点数值
DOUBLE 8 Bytes (-1.797 693 134 862 315 7 E+308,-2.225 073 858 507 201 4 E-308),0,(2.225 073 858 507 201 4 E-308,1.797 693 134 862 315 7 E+308) 0,(2.225 073 858 507 201 4 E-308,1.797 693 134 862 315 7 E+308) 双精度浮点数值
DECIMAL 对DECIMAL(M,D) ,如果M>D,为M+2否则为D+2 依赖于M和D的值 依赖于M和D的值 小数值
边栏推荐
- UE5 GAS 学习笔记 1.7 任务Ability Tasks
- Examples of AC simulation and S-parameter simulation of ADS simulation
- Introduction to CC cable of USB type-C
- Mongodb initialization operation
- 当Golang遇到高并发秒杀
- Introduction to main parameters of antenna
- 微信公众号授权登录后报redirect_uri参数错误的问题
- Ue5 gas learning notes 1.2 game Tags
- .net swagger
- First understanding of structure
猜你喜欢

Examples of AC simulation and S-parameter simulation of ADS simulation

欧美六国最快5日达 菜鸟推出快线产品 优化“端到端”履约服务

直播|StarRocks 技术内幕 :低基数全局字典优化

Gaode map realizes customized small blue dots, customized point markers, drawing polygon / circular areas, and displaying or hiding customized point markers according to the movement of the map

Introduction to main parameters of antenna

Record your interview experience in Xiamen for two years -- Conclusion

WordPress prompt error in establishing database connection

insight! Baidu pushed redis ceiling notes, which was originally understood by the database

苹果开发完整的苹果证书与描述文件创建流程

Introduction to the principle of signal source
随机推荐
当Golang遇到高并发秒杀
Details of iptables firewall
多线程与高并发—— 源码解析 AQS 原理
Implementation of solid transfer function (based on transfer)
Brief introduction: basic principle of srv6
Ue5 gas learning notes 1.8 game special effects (gameplaycue)
@Autowired与@Resource区别
iptables 配置
"Cloud strategy" will become an important pillar of enterprise digital transformation
haproxy实现灰度发布
Ue5 gas learning notes 0.1 case Preview
Ue5 gas learning notes 1.7 task ability tasks
Introduction to advanced design system (ads) 2009 RF simulation
MySQL日期函数
Calibration of vector network analyzer (vector network)
Go并发详解之一
leetcode 二叉树类
VSC上写Go出现expected ‘package‘, found ‘EOF‘
高德地图实现自定义小蓝点 自定义点标记 绘制多边形/圆形区域 根据地图的移动显示或者隐藏自定义点标记的相关实现
Docker搭建Mysql主从复制