Link to home
Start Free TrialLog in
Avatar of MOSTAGHASSI
MOSTAGHASSIFlag for United States of America

asked on

What is best solution a "photo table" or "photo field" in a database?

Hi all;
I would like to know that what is best approch for a photo table that keep photos for an article table and why?

I have a table for articles and each article can have zero or several photos:

1-putting a fileds in article table for photos and put the "file name" of each photo with separator in that field.

2-creat a table for photos and link it to articletable like:

tb_articles|article_id(pk) , title , subtitle , textbody , source_id(fk) , date , remark
tb_photos|photo_id(pk) , photofilename
tb_articles_photo|id(pk), photo_id(fk),article_id(fk)

thanks
Avatar of theGhost_k8
theGhost_k8
Flag of India image

tb_articles
article_id(pk) , title , subtitle , textbody , source_id(fk) , date , remark

tb_photo
photo_id,article_id, caption,photo_file

Or

tb_articles
article_id(pk) , title , subtitle , textbody , source_id(fk) , date , remark, photo_file(Comma separated)

1st is better.
ASKER CERTIFIED SOLUTION
Avatar of theGhost_k8
theGhost_k8
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
@MOSTAGHASSI, do not put photos into your data base tables.  Instead store the file name of the photo in your data base and store the photos themselves in the server file system.  There are many reasons why you want to do this, but performance and back up come to mind immediately.

You can easily generate a unique file name for the photos using a combination of the date/time and the owner key.

If you have many photos per article (zero - to - infinity) you want a separate table of photo names with a key to the articles that the photo applies to.

Best, ~Ray
I hope by "photofilename"  MOSTAGHASSI meant file path/to/photo only!!!
If not mean it...
Avatar of MOSTAGHASSI

ASKER

Thanks for all comments.
Yes ,this is just file name and the file store in a folder.