如果我有下表:
Product
+----+------+
| id | name |
+----+------+
| 1 | box |
| 2 | car |
| 3 | ball |
+----+------+
Color
+----+-------+
| id | name |
+----+-------+
| 1 | red |
| 2 | green |
| 3 | blue |
+----+-------+
Size
+----+--------+
| id | number |
+----+--------+
| 1 | 1 |
| 2 | 5 |
| 3 | 10 |
+----+--------+
Color Options (#product | #color)
+---------+-------+
| product | color |
+---------+-------+
| 1 | 1 |
| 1 | 3 |
| 3 | 1 |
| 3 | 2 |
| 2 | 3 |
+---------+-------+
Size Options (#product | #size)
+---------+-------+
| product | color |
+---------+-------+
| 1 | 1 |
| 1 | 2 |
| 3 | 1 |
| 3 | 2 |
| 2 | 2 |
| 2 | 3 |
+---------+-------+
当我删除一个产品时,删除它与颜色和尺寸的关系的最佳方法是什么?我是否需要在每个表中进行删除或是否有任何自动过程?
最佳答案
您是否为您的 mysql 设置了正确的RELATIONSHIP? 你可以引用这个问题 How to create relationships in MySQL和 MySQL foreign key constraints, cascade delete
关于mysql - 删除与其他表有关系的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16335659/