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

Link to comment
Share on other sites

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"

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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