当前位置:网站首页>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的值 小数值
边栏推荐
- Iptables configuration
- Go's walk library reports an error
- 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
- Leetcode79 method 1: deep search
- First understanding of structure
- Digital torrent: resource reorganization and strategic conflict in enterprise transformation
- Syntax error: non declaration statement outside function bodygo and syntax error: unexpected {, expect
- Iptables防火墙详细介绍
- What role does low code play in the digital transformation?
- 数字化洪流 :企业转型中的资源重组与战略冲突
猜你喜欢

"Cloud strategy" will become an important pillar of enterprise digital transformation

Shenzhen offline registration starrocks on AWS: how to conduct rapid unified analysis of real-time data warehouses

DC simulation example of ADS simulation

NPM cannot recognize the "NPM" item as the name of a cmdlet, function, script file, or runnable program. Please check the spelling of the name. If the path is included, make sure the path is correct,

WordPress prompt error in establishing database connection

LeetCode_63_不同路径Ⅱ

Introduction to the principle of signal source

Random talk on GIS data (VI) - projection coordinate system

Cloud container and cloud native

Internet intelligence, how to define the next generation network transformation
随机推荐
直播|StarRocks 技术内幕 :低基数全局字典优化
Wired: who owns the art of the future? Openai allows dall-e users to commercialize their works. At present
明德生物:公司暂未有产品被列入WHO推荐清单
Seven steps, in-depth interpretation of data meaning
NPM cannot recognize the "NPM" item as the name of a cmdlet, function, script file, or runnable program. Please check the spelling of the name. If the path is included, make sure the path is correct,
LeetCode79题 方法一:深度搜索
多线程与高并发—— 源码解析 AQS 原理
What role does low code play in the digital transformation?
syntax error: non-declaration statement outside function bodygo 和 syntax error: unexpected {, expect
Syntax error: non declaration statement outside function bodygo and syntax error: unexpected {, expect
Golang并发模型之
Performance parameters of spectrum analyzer
MongoDB数据库shell命令执行
npm 无法将“npm”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写,如果包括路径,请确保路径正确,然后再试一次。
Shenzhen offline registration starrocks on AWS: how to conduct rapid unified analysis of real-time data warehouses
iptables 配置
solidity转账函数的实现(基于transfer)
Mongodb create index
Docker搭建Mysql主从复制
Brief introduction: basic principle of srv6