DELETE
a,b,c
FROM
sp_movie.movie_db AS a
INNER JOIN sp_movie.movie_time AS b
ON a.Movie_ID = b.Movie_ID
INNER JOIN sp_movie.movie_time AS c
ON c.Movie_ID = a.Movie_ID
WHERE
a.Movie_ID = 29
我想刪除所有從具有Movie_ID = 29
有外鍵約束,同時使用內刪除行加入
所有三個表我甚至嘗試寫這 DELETE a FROM.....
我有行錯誤:Error Code: 1451. Cannot delete or update a parent row: a foreign key constraint fails (
sp_movie .
movie_actor Movie_ID ) REFERENCES
movie_db (
Movie_ID ) ON DELETE NO ACTION ON UPDATE NO ACTION)
或引用動作外鍵設置爲
on cascade
解決它更重要的是,設置爲'ON DELETE CASCADE'外鍵的操作,然後只從父表中刪除,讓MySQL爲你完成剩下的工作。 – eggyal@eggyal這似乎是一個好主意! Gotto檢查我的設置是什麼, –
@eggyal這不一定更好,有些情況下他不希望刪除級聯;我認爲最好保證安全 –