在我的网站上,我想删除一系列删除。也就是说,如果删除主类别,则将删除所有关联的子类别和子子类别。为此,我写了下面的查询,
UPDATE tabel1 AS t1
JOIN tabel2 AS t2 ON t2.foreignkey = t1.primarykey
JOIN tabel3 AS t3 ON t3.foreignkey = t2.primarykey
JOIN tabel4 AS t4 ON t4.foreignkey = t3.primarykey
SET t1.status = 'deleted',
t2.status = 'deleted',
t3.status = 'deleted',
t4.status = 'deleted'
WHERE
t1.primarykey = '1'
这个查询很有效,每个表中都有相应的外键。假设最后一个表是否用于存储图像。并且不一定要为表3数据添加图像。因此,如果使用上述查询,则在找到没有相应table4图像数据的table3数据时失败。但我也需要删除表3的数据。有没有办法实现它?