我可以擁有它們嗎?MYsql中的child-parent約束?
我有強迫,如果從不同的表中的相關行被刪除的行刪除約束:
node INT UNSIGNED NOT NULL,
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
name VARCHAR(20) NOT NULL,
title VARCHAR(200) NOT NULL,
description MEDIUMTEXT,
category VARCHAR(20) NOT NULL,
parent INT UNSIGNED DEFAULT 0, # here is the parent term id
# if it's 0 the term has no parent
PRIMARY KEY(id),
UNIQUE KEY(name, node, category),
KEY parent(parent),
KEY category(category),
CONSTRAINT terms FOREIGN KEY(node)
REFERENCES nodes(id) ON DELETE CASCADE ON UPDATE RESTRICT
我想迫使如果「家長」一詞行的自動刪除另一個約束被刪除? (如果有一個長期父集)
例子:
node | id | name | title | description | category | parent
___________________________________________________________________
534 | 1 | A | Foooooo | Bla bla... | A | 0
54 | 2 | B | Foooooo | Bla bla... | A | 1
45 | 3 | C | Foooooo | Bla bla... | A | 2
545 | 4 | D | Foooooo | Bla bla... | A | 2
534 | 5 | E | Foooooo | Bla bla... | A | 1
這樣的術語是這樣的:
A
- B
--- C
--- D
- E
所以,如果我刪除B,我想C和d被刪除,以及, 如果我刪除A,則B,C,d,E應刪除...