OneToMany关系。如何删除行?

2020年2月20日 41点热度 0条评论 来源: Николай Беляков

my database structureOneToMany关系。如何删除行?

你好。我刚刚学会了如何选择所有相关的数据,比方说,行 tennismatch.ID = 1:

SELECT * FROM tennismatch m 
JOIN tennismatch_tennisset ms 
ON m.`ID` = ms.`TennisMatch_ID` 
JOIN tennisset s 
ON ms.`mapOfSets_ID` = s.`ID` 
JOIN tennisset_game sg 
ON s.`ID` = sg.`TennisSet_ID` 
JOIN game g 
ON sg.`gamesMap_ID` = g.`ID` 
JOIN game_point gp 
ON g.`ID` =gp.`Game_ID` 
JOIN point p 
ON gp.`points_ID` = p.`ID` 
WHERE m.`ID` = 1 

,但我想不出如何删除这一切。 非常感谢提前。

===========解决方案如下:

使用DELETE JOIN语句

DELETE m, s, g, p, ms, sg, gp 
FROM tennismatch m 
JOIN tennismatch_tennisset ms ON m.ID = ms.TennisMatch_ID 
JOIN tennisset s ON ms.mapOfSets_ID = s.ID 
JOIN tennisset_game sg ON s.ID = sg.TennisSet_ID 
JOIN game g ON sg.gamesMap_ID = g.ID 
JOIN game_point gp ON g.ID = gp.Game_ID 
JOIN point p ON gp.points_ID = p.ID 
WHERE m.ID = 1 
    原文作者:Николай Беляков
    原文地址: https://stackoverflow.com/q/44749892
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。