当前位置:网站首页>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.
边栏推荐
- 无代码平台多行文字入门教程
- 罗克韦尔AB PLC RSLogix5000中定时器指令使用方法介绍
- Could you please talk about how the website is accessed?[Interview questions in the web field]
- gom登录器配置教程_谷歌浏览器如何使用谷歌搜索引擎
- safe-point(safepoint 安全点) 和 safe-region(安全区域)「建议收藏」
- 无线Mesh自组网方案,CV5200无线模组应用,支持高清数据远距离传输
- 数据使用要谨慎——不良数据带来严重后果
- Four common methods of network attacks and their protection
- 关于DSP驱动外挂flash
- 使用ClickHouse分析COS的清单和访问日志
猜你喜欢
蜜芽CEO刘楠:垂直电商黄金时代已落幕 坚定转型品牌之路
Multimedia and Internet of Things technology make the version "live" 129 vinyl records "Centennial Voice"
[Punctuality Atom STM32 Serial] Chapter 4 STM32 First Experience Excerpted from [Punctual Atom] MiniPro STM32H750 Development Guide_V1.1
Qt:小的任务管理器(task)
Win11系统重装用什么好 一键重装Win11教程
Anton Paar Anton Paar Density Meter Hydrometer Repair DMA35 Performance Parameters
rk3399-339 usb设备复合 总体流程
冰蝎工具开发实现动态二进制加密WebShell
Shell编程的条件语句
多媒体和物联网技术让版本“活”起来 129张黑胶唱片“百年留声”
随机推荐
MindSpore:损失函数问题
canvas画图时的bug记录
双向带头循环链表实现
一文带你了解 ESLint
各位大佬,请问mysql数据的cdc,能指定存量数据同步的zone为utc 吗
leetcode每天5题-Day06
OAK-FFC-4P全网首次测试
Win11不识别蓝牙适配器的解决方法
超宽带UWB实时精准定位,短距离无缝交互应用,物联网厘米级精度方案
Inheritance and the static keyword
浅聊偏函数
《福格行为模型》:如何养成好习惯?
Detailed explanation of NAT/NAPT address translation (internal and external network communication) technology [Huawei eNSP]
LVS+Keepalived群集部署
Detailed Explanation of Addresses Delivered by DHCP on Routing/Layer 3 Switches [Huawei eNSP]
XCTF-easy_Maze
学习在微信小程序中判断url的文件后缀格式
[论文翻译] Unpaired Image-to-Image Translation using Adversarial Consistency Loss
无代码平台单项选择入门教程
常用的输入对象