Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which data type should be used for saving images in database? [closed]

We are developing an E-commerce website using ASP.net and SQL server. The customer can view and order a wide variety of switches and light fittings.

As we need to display images of these products for each category, the number of images we need to display may rise to over 500. We are a bit confused by whether we should save these images as Image type in SQL, or whether it's better to store the path of the image. In the latter case, is storing all images under single folder better?

like image 909
Supreeth sup Avatar asked Apr 20 '15 11:04

Supreeth sup


People also ask

Which data type is used for image?

The following types are commonly used for images: Byte: An 8-bit unsigned integer ranging from 0 to 255. Pixels in images are commonly represented as byte data. Unsigned Integer: A 16-bit unsigned integer ranging from 0 to 65535.

What is the best way to save images in database?

The first is to store the file as a blob within the database. The second is to save the file (image, whatever) in a folder (which may be within the database folder structure) and then store the filename in a text field within the database.


1 Answers

The image data type has nothing to do with images. I don't know why it exists. It is legacy.

Store the images like you would store any other blob: varbinary(max).

The issue whether to store blobs in the database at all has been discussed before. Note, that the answers there are very opinionated and subjective. It is clearly wrong to say that one should always store blobs inside out outside of the database.

like image 84
usr Avatar answered Nov 17 '22 13:11

usr