当前位置:网站首页>MySQL: Integrity Constraints and Table Design Principles
MySQL: Integrity Constraints and Table Design Principles
2022-08-04 10:01:00 【_Sauron】
Article table of contents
Integrity constraints
- Primary key constraint: primary key
- Auto-increment key constraint: auto_increment
- Unique key constraint: unique
- Not null constraint: not null
- Default value constraint: default
- Foreign key constraint: foreign key
Only one primary key can be created in a table, but there can be multiple unique keys.
Example of usage:
CREATE TABLE user(
id INT UNSIGNED PRIMARY KEY AUTO_INCREMENT,
nickname varchar(50) UNIQUE NOT NULL,
age TINYINT UNSIGNED NOT NULL DEFAULT 18,
sex ENUM('male','female'));
Relational database table design
1. One to One
As shown in the figure, these are two tables, one for basic user information and one for identity information.
If you want to associate the two tables, you need to add a field to the identity information table
2. One-to-many
For example, to make an e-commerce system
- User User
- Product Product
- Order Order
Analysis:
Users and products: no relationship
Users and orders: one-to-many relationship
products and orders: many-to-many relationship
One-to-many relationship: Add a column to the order sub-table to associate the primary key of the parent table (the field representing the user id).But in this way, it is obvious that data redundancy, especially with hundreds or thousands of orders, will lead to large batches of modifications.
3. Many-to-many
In order to solve the problem of data redundancy, an intermediate table can be created.
边栏推荐
- 低代码是开发的未来吗?浅谈低代码开发平台的发展现状及未来趋势
- 【cookie 临时存储数据,WebStorage ,sessionStorage】
- ps如何换背景颜色,自学ps软件photoshop2022,3种不同的方式笔记记录
- leetcode动态规划系列(求路径篇)
- Win11系统重装用什么好 一键重装Win11教程
- 暴力破解-破解 Apache BASIC 认证
- [Punctuality Atom STM32 Serial] Chapter 4 STM32 First Experience Excerpted from [Punctual Atom] MiniPro STM32H750 Development Guide_V1.1
- MindSpore:损失函数问题
- [Punctuality Atom STM32 Serial] Chapter 3 Development Environment Construction Excerpted from [Punctual Atom] MiniPro STM32H750 Development Guide_V1.1
- leetcode动态规划经典例题——53.最大子数组和
猜你喜欢
无代码平台描述文字入门教程
无代码平台数字入门教程
《福格行为模型》:如何养成好习惯?
无线Mesh自组网方案,CV5200无线模组应用,支持高清数据远距离传输
二叉树与堆
EastWave应用:自动计算光子晶体透反率
Detailed explanation of MSTP protocol configuration on Layer 3 switches [Huawei eNSP experiment]
Detailed explanation of NAT/NAPT address translation (internal and external network communication) technology [Huawei eNSP]
DOM简述
Detailed explanation of switch link aggregation [Huawei eNSP]
随机推荐
【cookie 临时存储数据,WebStorage ,sessionStorage】
菲沃泰科创板上市:市值123亿 宗坚赵静艳夫妇身价76亿
OAK-FFC-4P全网首次测试
Techwiz OLED:OLED器件的发光效率
Win11系统重装用什么好 一键重装Win11教程
无代码平台单项选择入门教程
Layer 3 Switch/Router OSPF Configuration Details [Huawei eNSP Experiment]
After four years of outsourcing, the autumn recruits finally landed
无代码平台数字入门教程
Could you please talk about how the website is accessed?[Interview questions in the web field]
SVG 的 path 属性绘制图形
Producer and Consumer Problems in Concurrent Programming
无线Mesh自组网方案,CV5200无线模组应用,支持高清数据远距离传输
MindSpore:【mindinsight】【Profiler】用execution_time推导出来的训练耗时远小于真实的耗时
MySQL binlog都有哪些模式?
LeetCode中等题之设计循环队列
浅聊偏函数
TCP协议 - 三次握手 - 四次挥手-内核参数调优
Detailed explanation of switch link aggregation [Huawei eNSP]
蜜芽CEO刘楠:垂直电商黄金时代已落幕 坚定转型品牌之路