当前位置:网站首页>多表操作-外键级联操作
多表操作-外键级联操作
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;
边栏推荐
- QT等待框制作
- JS random verification code
- Usage and principle of synchronized
- Design and application of immutable classes
- Global and Chinese market of enterprise wireless LAN 2022-2028: Research Report on technology, participants, trends, market size and share
- LevelDB源码分析之memtable
- Memtable for leveldb source code analysis
- More than one file was found with OS independent path ‘lib/armeabi-v7a/libyuv.so‘.
- 如何开始学剪辑?零基础详细解析
- 数字金额加逗号;js给数字加三位一逗号间隔的两种方法;js数据格式化
猜你喜欢

Things generated by busybox
![[RootersCTF2019]babyWeb](/img/b4/aa8f8e107a9dacbace72d4717b1834.png)
[RootersCTF2019]babyWeb

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

如何选择导电滑环材料

Memtable for leveldb source code analysis

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

Summary of spanner's paper

实战:redux的基本使用

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

Application of industrial conductive slip ring
随机推荐
Spanner 论文小结
Global and Chinese market for kitchen range hoods 2022-2028: Research Report on technology, participants, trends, market size and share
Flowable source code comment (XXXIX) task listener
[RootersCTF2019]babyWeb
了解 JVM 中几个相关问题 — JVM 内存布局、类加载机制、垃圾回收
Simple read / write verification of qdatastream
Global and Chinese market of solder wire 2022-2028: Research Report on technology, participants, trends, market size and share
导电滑环短路的原因以及应对措施
El cascade echo failed; El cascader does not echo
轻松上手Fluentd,结合 Rainbond 插件市场,日志收集更快捷
1076 Forwards on Weibo
Set set detailed explanation
Global and Chinese markets of InGaAs APD arrays 2022-2028: Research Report on technology, participants, trends, market size and share
工业导电滑环的应用
Implementation of distributed lock
基于TI DRV8424驱动步进电机实现调速和行程控制
AcWing 888. Finding combinatorial number IV (the problem of finding combinatorial number with high precision)
Redis database deployment and common commands
Web Security (x) what is OAuth 2.0?
Global and Chinese markets of gps/gnss receiver modules 2022-2028: Research Report on technology, participants, trends, market size and share








