我可以拥有它们吗?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应删除...