我有一张桌子tree
:
+------+-------+
| id | name |
+------+-------+
| 0 | tree1 |
| 1 | tree2 |
| 2 | tree3 |
| 3 | tree4 |
+------+-------+
一张桌子pen
:
+------+------+
| id | name |
+------+------+
| 0 | pen1 |
| 1 | pen2 |
| 2 | pen3 |
| 3 | pen4 |
+------+------+
第三个表task
将任务“附加”到树或笔:
+------+------+-------+
| type | id | name |
+------+------+-------+
| 0 | 1 | foo |
| 0 | 2 | bar |
| 1 | 1 | fee |
| 1 | 2 | beer |
+------+------+-------+
当type
为 0 时,表示id
引用 a tree
。当type
为 1 时,它引用 a pen
(以此类推许多不同的表)。
我怎样才能做到这一点并确保参照完整性?