Cascade級聯刪除的簡單理解

2021-09-16 13:05:56 字數 1356 閱讀 1035

可以先簡單理解成:觸發器

讓我們舉個栗子

在資料庫建三個表:a(主表),aa,aaa

-- 表a

create table a(

id int primary key,

age int

)-- 表aa,沒有級聯

create table aa(

id1 int primary key,

age1 int,

foreign key(id1) references a(id)

)-- 表aaa,設定級聯刪除

create table aaa(

id2 int primary key,

age2 int,

foreign key(id2) references a(id) on delete cascade

)

對各表插入資料

insert into a values ('001','001');

insert into a values ('002','002');

insert into aa values ('001','0011');

insert into aaa values ('002','0022');

2.1. 檢視一下此時各表的資料

select id 'a表id',age from a;

select id1 'aa表id',age1 from aa;

select id2 'aaa表id',age2 from aaa;

對主表進行記錄刪除操作

delete from a where id = 1; -- 無法刪除

delete from a where id = 2; -- 可刪除

再檢視一下各表

select id 'a表id',age from a; -- 少了一條記錄

select id1 'aa表id',age1 from aa; -- 無變化

select id2 'aaa表id',age2 from aaa; -- 無紀錄

Cascade級聯刪除的簡單理解

cascade級聯刪除的簡單理解 可以先簡單理解成 觸發器 讓我們舉個栗子 在資料庫建三個表 a 主表 aa,aaa 表a create table a id intprimary key,age int 表aa,沒有級聯 create table aa id1 intprimary key,age...

Cascade級聯刪除的簡單理解

cascade級聯刪除的簡單理解 可以先簡單理解成 觸發器 讓我們舉個栗子 在資料庫建三個表 a 主表 aa,aaa 表a create table a id intprimary key,age int 表aa,沒有級聯 create table aa id1 intprimary key,age...

CSS樣式權重的級聯cascade的概念深入理解

我們知道,firefox在眾多瀏覽器中是對css 2高度相容的一款瀏覽器,那是我能夠編寫乙個中型b2b 的時候 並不能說是我遇到過的難題 在禪意花園中看到的乙個案例,說的是某個選單在css中定義了以後只能在firefox中正常顯示。因為那個css涉及的濾鏡太多,而且還有css中 級聯 cascade...