当我用外键删除行时,有一种方法可以删除引用的记录?这是我的数据库表和我想删除3记录引用的表"权利"当我删除表"卡特尔">
中的记录时在另一个方向添加引用,像这样:
小提琴
-- cartelle (folder)
CREATE TABLE folders ( folder_id int primary key );
-- righe (rows, tied to a folder)
CREATE TABLE xrows (
row_id int primary key
, folder_id int
, FOREIGN KEY (folder_id) REFERENCES folders (folder_id) ON DELETE CASCADE
);
INSERT INTO folders VALUES (1), (2), (3);
INSERT INTO xrows VALUES
(1, 1)
, (2, 1)
, (3, 1)
, (4, 2)
, (5, 3)
, (6, 2)
;
<表类>
row_id
folder_id
tbody><<tr>1 1 21 3 1 42 53 62 表类>