让我们考虑使用"树"以id
为主键的表。
一个"链接"具有(src_id
,dst_id
)作为主键的表和那些外键:
src_id
(引用tree
表)dst_id
(也引用tree
表)我们如何选择特定树源的所有来源(不要疯狂)?
编辑:
SQL> DESC tree;
+---------+---------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+---------------+------+-----+---------+-------+
| id | int(11) | NO | PRI | | |
+---------+---------------+------+-----+---------+-------+
5 rows in set (0.00 sec)
SQL> DESC link;
+---------+---------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+---------------+------+-----+---------+-------+
| src_id | int(11) | NO | FK | | |
| dst_id | int(11) | NO | FK | | |
+---------+---------------+------+-----+---------+-------+
5 rows in set (0.00 sec)