当前位置:网站首页>多表操作-外键级联操作
多表操作-外键级联操作
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;
边栏推荐
- Global and Chinese market of 3D CAD 2022-2028: Research Report on technology, participants, trends, market size and share
- Variable binding and deconstruction for rudimentary rust
- Like cloud functions
- Global and Chinese markets for business weather forecasting 2022-2028: Research Report on technology, participants, trends, market size and share
- Global and Chinese market of high-end home theater 2022-2028: Research Report on technology, participants, trends, market size and share
- 液压滑环的特点讲解
- Global and Chinese market for kitchen range hoods 2022-2028: Research Report on technology, participants, trends, market size and share
- Redis database deployment and common commands
- Go learning notes (5) basic types and declarations (4)
- [ffmpeg] [reprint] image mosaic: picture in picture with wheat
猜你喜欢

tar命令

STM32 expansion board digital tube display

智慧运维:基于 BIM 技术的可视化管理系统

导电滑环短路的原因以及应对措施

Leetcode1497- check whether array pairs can be divided by K - array - hash table - count

複制寶貝提示材質不能為空,如何解决?

Tar command

Redis database deployment and common commands

使用 Nocalhost 开发 Rainbond 上的微服务应用

Mathematical knowledge: finding the number of divisors
随机推荐
1076 Forwards on Weibo
Global and Chinese market of protection circuit modules 2022-2028: Research Report on technology, participants, trends, market size and share
Global and Chinese market of metal oxide semiconductor field effect transistors 2022-2028: Research Report on technology, participants, trends, market size and share
Tar command
基于TI DRV8424驱动步进电机实现调速和行程控制
使用 Nocalhost 开发 Rainbond 上的微服务应用
Spanner 论文小结
Single page application
Global and Chinese market of mainboard 2022-2028: Research Report on technology, participants, trends, market size and share
QT等待框制作
STM32 expansion board digital tube display
Global and Chinese market for instant messaging security and compliance solutions 2022-2028: Research Report on technology, participants, trends, market size and share
LevelDB源码分析之LRU Cache
Set集合详细讲解
Web Security (IX) what is JWT?
C WPF uses dockpanel to realize screenshot box
Global and Chinese market of enterprise wireless LAN 2022-2028: Research Report on technology, participants, trends, market size and share
printk 调试总结
AcWing 888. Finding combinatorial number IV (the problem of finding combinatorial number with high precision)
[data recovery in North Asia] a data recovery case of raid crash caused by hard disk drop during data synchronization of hot spare disk of RAID5 disk array








