开发者

mysql : using FK to delete rows from parent table that dont match with child table

Lets say there are 2 tables with the following definitions: photos_libraries ( id , name ) and photos ( id , library_id )

when a row in photos is deleted or updated I'd like to run the functionality of :

delete from photos_libraries where id not in ( select 开发者_StackOverflowlibrary_id from photos )

Is there a way to do that using a foreign key ?


Check out ON DELETE CASCADE.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜