当前位置:网站首页>多表操作-外键级联操作
多表操作-外键级联操作
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;
边栏推荐
- Redis database deployment and common commands
- One click deployment of highly available emqx clusters in rainbow
- Global and Chinese market for kitchen range hoods 2022-2028: Research Report on technology, participants, trends, market size and share
- eBPF Cilium实战(2) - 底层网络可观测性
- Global and Chinese market of high-end home theater 2022-2028: Research Report on technology, participants, trends, market size and share
- Some common commands of podman
- QT等待框制作
- Manually implement a simple stack
- Global and Chinese market of enterprise wireless LAN 2022-2028: Research Report on technology, participants, trends, market size and share
- Dynamic verification of new form items in El form; El form verifies that the dynamic form V-IF does not take effect;
猜你喜欢

Day 05 - file operation function

Distributed transactions - Solutions

Tcp/ip explanation (version 2) notes / 3 link layer / 3.2 Ethernet and IEEE 802 lan/man standards

轻松上手Fluentd,结合 Rainbond 插件市场,日志收集更快捷

TypeORM 框架

复制宝贝提示材质不能为空,如何解决?

Unity项目心得总结

Redis database deployment and common commands

Single page application

Things generated by busybox
随机推荐
Memtable for leveldb source code analysis
Intelligent operation and maintenance: visual management system based on BIM Technology
Global and Chinese market of enterprise wireless LAN 2022-2028: Research Report on technology, participants, trends, market size and share
Global and Chinese market of 3D design and modeling software 2022-2028: Research Report on technology, participants, trends, market size and share
3D建模與處理軟件簡介 劉利剛 中國科技大學
Vmware workstation network card settings and three common network modes
AcWing 889. 01 sequence satisfying the condition (Cartland number)
智慧运维:基于 BIM 技术的可视化管理系统
Data consistency between redis and database
Global and Chinese markets of gps/gnss receiver modules 2022-2028: Research Report on technology, participants, trends, market size and share
复制宝贝提示材质不能为空,如何解决?
C WPF uses dockpanel to realize screenshot box
RecycleView的一些使用
Tcp/ip explanation (version 2) notes / 3 link layer / 3.2 Ethernet and IEEE 802 lan/man standards
Using nocalhost to develop microservice application on rainbow
使用 Nocalhost 开发 Rainbond 上的微服务应用
Global and Chinese markets of InGaAs APD arrays 2022-2028: Research Report on technology, participants, trends, market size and share
Manually implement a simple stack
工业导电滑环的应用
[Yugong series] February 2022 Net architecture class 005 ABP vNext Net core web application getting started configuration








