开发者

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

开发者 https://www.devze.com 2022-12-11 09:54 出处:网络
I have a table for articles with several field开发者_运维技巧s ,each article can havephoto/photos ,is it good that have a field for photo in article_table or i make another table for photo/photos and

I have a table for articles with several field开发者_运维技巧s ,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


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


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.


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

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

0

精彩评论

暂无评论...
验证码 换一张
取 消