chelnov63 Posted August 5, 2008 Share Posted August 5, 2008 Hope i can explain this well ... I have a gallery system with two tables: (1) GallerySets - this table contains two columns - ID(Primary Key) and GalleryName (2) GalleryImages - this contains the columns ID(Primary Key) and GalleryID(Foreign Key) and ImageURL GalleryImages basically contains all the image urls relating to the gallery sets in the table GallerySets Now suppose a CMS admin has the option to delete image records from GalleryImages (one or multiple images).. suppose he deletes all records from GalleryImage which have a GalleryID of 70 ..that causes an issue - as in the GallerySets table their is still a Gallery Set with ID = 70, but no corresponding images in GalleryImages... how do i get around this? thanks in advance.. Quote Link to comment https://forums.phpfreaks.com/topic/118234-deleting-records-from-foreign-key-table-but-then-need-to-delete-primary-key-row/ Share on other sites More sharing options...
ignace Posted August 5, 2008 Share Posted August 5, 2008 use the proper db engine (e.g. innodb) and use references http://mirror.yandex.ru/mirrors/ftp.mysql.com/doc/refman/5.0/en/innodb-foreign-key-constraints.html then when you delete the parent table all child tables will be also deleted or restricted, if all images within an album are deleted, then there is no problem, just show "no images available for this album" Quote Link to comment https://forums.phpfreaks.com/topic/118234-deleting-records-from-foreign-key-table-but-then-need-to-delete-primary-key-row/#findComment-608525 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.