开发者

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

开发者 https://www.devze.com 2023-03-23 07:43 出处:网络
Lets say there are 2 tables with the following definitions: photos_libraries ( id , name ) and photos ( id , library_id )

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

精彩评论

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