在数据库中,我有一个用户名表和一个权限表。我还有一个中间表,可以将用户分配到一个或多个司法管辖区。
employee table
userID (primary Key)
firstName
lastName
records:
+--------+-----------+----------+
| userID | firstName | lastName |
+--------+-----------+----------+
| 6 | John | Doe |
| 11 | lisa | lopez |
+--------+-----------+----------+
jurisdictions table
jurId (Primary Key)
region
records:
+-------+--------------+
| jurID | jurisdiction |
+-------+--------------+
| 1 | California |
| 2 | Texas |
| 3 | Washington |
| 4 | South Dakota |
| 5 | Alaska |
| 6 | Ohio |
+-------+--------------+
user_jurisdiction
userID (Foriegn Key pointing to employees userID)
jurID (Foriegn Key pointing to jurisdictions jurID)
records:
+--------+-------+
| userID | jurID |
+--------+-------+
| 6 | 2 |
| 6 | 3 |
| 11 | 2 |
+--------+-------+
我想让它在哪里如果我删除父表行,具有相应外键的中间表将被自动删除。我制作了中间表:
CREATE TABLE user_jurisdiction(userID int NOT NULL, jurID int NOT NULL, FOREIGN KEY(userID) REFERENCES employee(userID) ON DELETE CASCADE, FOREIGN KEY (jurID) REFERENCES jurisdictions(jurID) ON DELETE CASCADE);
但是当我从父表中删除某些东西时......就像表 jurisidictions.jurisdiction 中的州名行...... userID 和 jurID 行不会自动从中间表 user_jurisdiction 中删除。据我所见,我在每个外键上都正确设置了 DELETE ON CASCADE。为什么删除父表行后,中间表中对应的外键行没有被删除?