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
.
精彩评论