Kaveh
Kaveh

Reputation: 2650

"Photo field" in "article_table" or independent table for photo?

I have a table for articles with several fields ,each article can have photo/photos ,is it good that have a field for photo in article_table or i make another table for photo/photos and why?

thanks

Upvotes: 0

Views: 128

Answers (3)

Damir Sudarevic
Damir Sudarevic

Reputation: 22187

Consider this -- each article can have many photos, each photo can appear in many articles.

articlewphoto_model_01

Upvotes: 0

wadesworld
wadesworld

Reputation: 13753

Since you mention "photos" plural, I'll assume you can have multiple photos per article.

In that case, you'd want an association table.

Something like:

ARTICLE
--------------
ID(pk)    NUMBER NOT NULL,
AUTHOR_ID NUMBER NOT NULL,
TITLE     VARCHAR NOT NULL,
CONTENT   CLOB NOT NULL

ARTICLE_PHOTO
-----------------
ARTICLE_ID NUMBER NOT NULL,
PHOTO_ID NUMBER NOT NULL

(ARTICLE_ID, PHOTO_ID) is the PK, and both ARTICLE_ID and PHOTO_ID are FKs

PHOTO
--------------------
ID(pk) NUMBER NOT NULL,
PHOTO  BLOB NOT NULL

Upvotes: 1

just somebody
just somebody

Reputation: 19247

if it's always exactly one image, then it's a matter of design. if the count can vary, then you must put it in a separate table, because otherwise you're in for trouble querying and updating the data.

Upvotes: 0

Related Questions