当前位置:网站首页>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;
边栏推荐
- Dynamic verification of new form items in El form; El form verifies that the dynamic form V-IF does not take effect;
- Design and application of immutable classes
- LevelDB源码分析之memtable
- Unity项目心得总结
- 新手在挖财开通证券账户安全吗?
- Daily question -leetcode1175- permutation of prime numbers - Mathematics
- Using nocalhost to develop microservice application on rainbow
- QT waiting box production
- TypeORM 框架
- Application of industrial conductive slip ring
猜你喜欢

How to hide browser network IP address and modify IP internet access?

Actual combat: basic use of Redux

Daily question -leetcode1175- permutation of prime numbers - Mathematics

在Rainbond中一键部署高可用 EMQX 集群

Summary of spanner's paper

Application of industrial conductive slip ring

数字金额加逗号;js给数字加三位一逗号间隔的两种方法;js数据格式化

Actual combat: gateway api-2022.2.13

数据库连接池的简单实现

Copier le matériel de conseils de bébé ne peut pas être vide, comment résoudre?
随机推荐
Daily question -leetcode1175- permutation of prime numbers - Mathematics
TypeORM 框架
CockroachDB 分布式事务源码分析之 TxnCoordSender
Using nocalhost to develop microservice application on rainbow
Introduction to 3D modeling and processing software Liu Ligang University of science and technology of China
Series of improving enterprise product delivery efficiency (1) -- one click installation and upgrade of enterprise applications
Global and Chinese markets of gps/gnss receiver modules 2022-2028: Research Report on technology, participants, trends, market size and share
How to start learning editing? Detailed analysis of zero basis
Mathematical knowledge: finding the number of divisors
液压滑环的特点讲解
Some common commands of podman
What can the points mall Games bring to businesses? How to build a points mall?
Numeric amount plus comma; JS two methods of adding three digits and a comma to numbers; JS data formatting
tar命令
How to hide browser network IP address and modify IP internet access?
Rust hello-word
Global and Chinese market of high-end home theater 2022-2028: Research Report on technology, participants, trends, market size and share
LRU cache for leveldb source code analysis
And search: the suspects (find the number of people related to the nth person)
2/15 (awk, awk conditions, awk processing design can perform additional tasks, and use awk array +for loop to realize advanced search)








