当前位置:网站首页>Multi table operation - foreign key cascade operation
Multi table operation - foreign key cascade operation
2022-07-01 05:29:00 【Soup key TJ】
Catalog
Cascade update and cascade delete of foreign key
Add cascade update and cascade delete at the same time
Add a foreign key constraint , Add cascade update and cascade delete at the same time
Cascade update and cascade delete of foreign key
What is cascading updates
- When I want to modify the data in the main table
- I expect that the associated data from the table will also be modified
What is cascade deletion
- When I want to delete the data in the main table
- I expect that the associated data from the table will also be deleted
Add cascading updates
- alter table Table name add
- constraint Foreign key name foreign key ( Foreign key column name of this table ) references Main table name ( Primary key column name )
- on update cascade;
Add cascade delete
- alter table Table name add
- constraint Foreign key name foreign key ( Foreign key column name of this table ) references Main table name ( Primary key column name )
- on delete cascade;
Add cascade update and cascade delete at the same time
- alter table Table name add
- constraint Foreign key name foreign key ( Foreign key column name of this table ) references Main table name ( Primary key column name )
- on update cascade on delete cascade;
Examples demonstrate
Add a foreign key constraint , Add cascade update and cascade delete at the same time

-- Add a foreign key constraint , Add cascade update and cascade delete at the same time ALTER TABLE ouser ADD CONSTRAINT ou FOREIGN KEY (uid) REFERENCES user(id) ON UPDATE CASCADE ON DELETE CASCADE;Test after adding
- Original form information


- Make changes



-- The user Li Si id Change it to 3,ouser In the table uid Also automatically modify UPDATE user SET id=3 WHERE id=2;


-- Delete the user Li Si ,ouser The related ownership in the table is also automatically deleted DELETE FROM user WHERE id=3;
边栏推荐
- CockroachDB 分布式事务源码分析之 TxnCoordSender
- Go learning notes (5) basic types and declarations (4)
- 0xc000007b the application cannot start the solution normally (the pro test is valid)
- Dynamic verification of new form items in El form; El form verifies that the dynamic form V-IF does not take effect;
- El cascade echo failed; El cascader does not echo
- Use and principle of AQS related implementation classes
- Unity project experience summary
- Numeric amount plus comma; JS two methods of adding three digits and a comma to numbers; JS data formatting
- Using nocalhost to develop microservice application on rainbow
- How to traverse massive data in redis
猜你喜欢

Rainbow combines neuvector to practice container safety management

基于TI DRV8424驱动步进电机实现调速和行程控制

Copier le matériel de conseils de bébé ne peut pas être vide, comment résoudre?

Leetcode top 100 question 2 Add two numbers

Set集合詳細講解

数据库连接池的简单实现

In depth understanding of condition source code interpretation and analysis of concurrent programming

Txncoordsender of cockroachdb distributed transaction source code analysis

How to select conductive slip ring material

小程序常用组件小结
随机推荐
printk 调试总结
RecycleView的一些使用
Data consistency between redis and database
CentOS 7使用yum安装PHP7.0
Explanation of characteristics of hydraulic slip ring
Thread process foundation of JUC
0xc000007b应用程序无法正常启动解决方案(亲测有效)
QT等待框制作
液压滑环的特点讲解
Mongodb学习篇:安装后的入门第一课
Software intelligence: the "world" and "boundary" of AI sentient beings in AAAs system
QDataStream的简单读写验证
Flutter 实现每次进来界面都刷新数据
C WPF uses dockpanel to realize screenshot box
Daily question -leetcode1175- permutation of prime numbers - Mathematics
Leetcode top 100 questions 1 Sum of two numbers
More than one file was found with OS independent path ‘lib/armeabi-v7a/libyuv.so‘.
Set集合詳細講解
Floweable source code annotation (40) class delegation
Things generated by busybox








