当前位置:网站首页>多表操作-外键级联操作
多表操作-外键级联操作
2022-07-01 05:22:00 【汤键.TJ】
目录
外键的级联更新和级联删除
什么是级联更新
- 当我想把主表中的数据进行修改时
- 我期望从表中有关联的数据也会随之修改
什么是级联删除
- 当我想把主表中的数据进行删除时
- 我期望从表中有关联的数据也会随之删除
添加级联更新
- alter table 表名 add
- constraint 外键名 foreign key (本表外键列名) references 主表名(主键列名)
- on update cascade;
添加级联删除
- alter table 表名 add
- constraint 外键名 foreign key (本表外键列名) references 主表名(主键列名)
- on delete cascade;
同时添加级联更新和级联删除
- alter table 表名 add
- constraint 外键名 foreign key (本表外键列名) references 主表名(主键列名)
- on update cascade on delete cascade;
实例演示
添加外键约束,同时添加级联更新和级联删除

-- 添加外键约束,同时添加级联更新和级联删除 ALTER TABLE ouser ADD CONSTRAINT ou FOREIGN KEY (uid) REFERENCES user(id) ON UPDATE CASCADE ON DELETE CASCADE;添加后测试
- 原表单信息


- 进行修改



-- 将李四这个用户的id改为3,ouser表中的uid也自动修改 UPDATE user SET id=3 WHERE id=2;


-- 将李四这个用户删除,ouser表中的相关所属也自动删除 DELETE FROM user WHERE id=3;
边栏推荐
- Fluentd is easy to use. Combined with the rainbow plug-in market, log collection is faster
- Worried about infringement? Must share copyrightless materials on the website. Don't worry about the lack of materials for video clips
- How to select conductive slip ring material
- Leetcode316- remove duplicate letters - stack - greedy - string
- 云原生存储解决方案Rook-Ceph与Rainbond结合的实践
- Global and Chinese markets of InGaAs APD arrays 2022-2028: Research Report on technology, participants, trends, market size and share
- Design and application of immutable classes
- What can the points mall Games bring to businesses? How to build a points mall?
- Usage and principle of synchronized
- Redis database deployment and common commands
猜你喜欢

Actual combat: basic use of Redux

小程序常用组件小结

C# wpf 使用DockPanel实现截屏框

Solution: drag the Xib control to the code file, and an error setvalue:forundefined key:this class is not key value coding compliant for the key is reported

Redis数据库的部署及常用命令

Software intelligence: the "world" and "boundary" of AI sentient beings in AAAs system

C WPF uses dockpanel to realize screenshot box

How to create a progress bar that changes color according to progress

Data consistency between redis and database

Leetcode316- remove duplicate letters - stack - greedy - string
随机推荐
数字金额加逗号;js给数字加三位一逗号间隔的两种方法;js数据格式化
提高企业产品交付效率系列(1)—— 企业应用一键安装和升级
Unity drags and modifies scene camera parameters under the editor
Floweable source code annotation (40) class delegation
移动端常用解决方案
AcWing 888. Finding combinatorial number IV (the problem of finding combinatorial number with high precision)
如何开始学剪辑?零基础详细解析
Use of STM32 expansion board temperature sensor and temperature humidity sensor
Data consistency between redis and database
Global and Chinese market of 3D CAD 2022-2028: Research Report on technology, participants, trends, market size and share
Global and Chinese market of paper machine systems 2022-2028: Research Report on technology, participants, trends, market size and share
Use and principle of AQS related implementation classes
Vérification simple de la lecture et de l'écriture de qdatastream
Some common commands of podman
Detailed explanation of set
busybox生成的东西
云原生存储解决方案Rook-Ceph与Rainbond结合的实践
Usage and principle of synchronized
AcWing 889. 01 sequence satisfying the condition (Cartland number)
Implementation of distributed lock








