MySQL Forums
Forum List  »  Newbie

Re: JOIN or Foreign key
Posted by: Felix Geerinckx
Date: May 12, 2005 10:40AM

Simon wrote:

> I am I correct in saying - if I am only person inputting data and make sure that I do not enter
> into the Images table a Property ID that does not exist in the Properties table, I could get by with
> just the 2 tables Properties & Images, as I do not need to have the Integrity checked?

No, that is not correct. A third table is necessary to model the many-to-many relationship between properties and images. Suppose you would add a foreign key property_id to the images table.

With the statement:

INSERT INTO images (id, path, property_id) VALUES(NULL, '/some/directory/image1.jpg', 1);

you would record that image.jpg is about the property with id = 1.

Now suppose image1.jpg also shows the property with id = 2. To record this, you would have to add:

INSERT INTO images (id, path, property_id) VALUES(NULL, '/some/directory/image1.jpg', 2);

The problem with this is that you have duplicated information. If you move image1.jpg to another directory e.g., you have to UPDATE several records.

With the three table model, you only have to update one record.

--
felix
Please use BBCode to format your messages in this forum.

Options: ReplyQuote


Subject
Written By
Posted
April 25, 2005 08:29AM
May 12, 2005 02:57AM
May 12, 2005 09:01AM
Re: JOIN or Foreign key
May 12, 2005 10:40AM
May 13, 2005 04:26AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.