tags:

views:

26

answers:

4

I'm programming site for ren-a-car company, and I need to save exactly three pictures for every car. What is better to store in database ( table description) path to images and images save in some folder OR to save pictures in table (MS SQL )?

+1  A: 

The main question is: how big are those pictures on average??

A thorough examination by Microsoft Research (To BLOB or Not To BLOB: Large Object Storage in a Database or a Filesystem) has shown:

  • that it's better to store stuff inside your SQL tables as long as the data is typically smaller than 256 KB
  • that it's better to store on filesystem if the elements are typically larger than 1 MB

The in-between is a bit of a gray area....

So: are you pictures mostly more than 1 MB?? Then store on disk and keep a reference. Otherwise, I'd recommend storing them inside your database table.

marc_s
A: 

Better to save the path to the picture (and probably even better just the filename usually). By storing the picture in the table, you are increasing the size of the tables and therefore increasing lookup time, insert time, etc for no apparent gain.

The other thing is that you say you need to save exactly 3 pictures for each posting, so this makes me think you're using fields in your posts table such as pic1, pic2, pic3. You might want to normalize this so that you have a post_pictures table that links each post with a picture.

For instance: post_pictures: post_picture_id | post_id | picture_filename. (you can even get away with having just two fields).

ajacian81
This is a bit of a crude piece of advice - if the pictures are typically pretty small, e.g. thumbnails, then storing them on disk actually performs significantly worse than storing them in the database table....
marc_s
A: 

Depending on the horsepower of your server farm, save in SQL. I have set the up fields as varbinary(max).

Glen Wilkinson
A: 

What advantage do you have in storing the images in database? Can you think of any use of the image data being stored in a DB?

I suggest you store the images in file system rather than database. You can use the database to store meta data of the images (path,keywords etc) in the database.

Abdel Olakara