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.
精彩评论