当前位置:网站首页>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;
边栏推荐
- Use and principle of Park unpark
- Design and application of immutable classes
- Printk debugging summary
- Worried about infringement? Must share copyrightless materials on the website. Don't worry about the lack of materials for video clips
- Unity drags and modifies scene camera parameters under the editor
- Global and Chinese markets of superconductor 2022-2028: Research Report on technology, participants, trends, market size and share
- Global and Chinese market of paper machine systems 2022-2028: Research Report on technology, participants, trends, market size and share
- tar命令
- Software intelligence: the "world" and "boundary" of AI sentient beings in AAAs system
- Intelligent operation and maintenance: visual management system based on BIM Technology
猜你喜欢

Leetcode522- longest special sequence ii- hash table - String - double pointer

TypeORM 框架

tar命令

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

Rainbow combines neuvector to practice container safety management

Series of improving enterprise product delivery efficiency (1) -- one click installation and upgrade of enterprise applications

Design and application of immutable classes

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

Actual combat: basic use of Redux

Usage and principle of synchronized
随机推荐
在Rainbond中一键部署高可用 EMQX 集群
Understand several related problems in JVM - JVM memory layout, class loading mechanism, garbage collection
数字金额加逗号;js给数字加三位一逗号间隔的两种方法;js数据格式化
Fluentd is easy to use. Combined with the rainbow plug-in market, log collection is faster
AcWing 885. Find the combination number I (recursive preprocessing)
Data consistency between redis and database
Daily question -leetcode1175- permutation of prime numbers - Mathematics
AcWing 889. 01 sequence satisfying the condition (Cartland number)
Global and Chinese market of metal oxide semiconductor field effect transistors 2022-2028: Research Report on technology, participants, trends, market size and share
Spanner 论文小结
[RootersCTF2019]babyWeb
Cockroachdb: the resistant geo distributed SQL database paper reading notes
How to traverse massive data in redis
Global and Chinese market of high-end home theater 2022-2028: Research Report on technology, participants, trends, market size and share
[ffmpeg] [reprint] image mosaic: picture in picture with wheat
[Yugong series] February 2022 Net architecture class 005 ABP vNext Net core web application getting started configuration
Vmware workstation network card settings and three common network modes
One click deployment of highly available emqx clusters in rainbow
Tcp/ip explanation (version 2) notes / 3 link layer / 3.2 Ethernet and IEEE 802 lan/man standards
eBPF Cilium实战(2) - 底层网络可观测性








