Jump to content

Deleting records from foreign key table, but then need to delete primary key row


chelnov63

Recommended Posts

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..

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"

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.