1

I am developing a system where I will be saving many images (approximately 100+). I researched and I've known that saving many images to the database will make the database's size grow immensely. So I am thinking of doing what many recommend which is to save the path or location of the image. But I'm afraid it is not applicable especially I am doing a thesis. What conflicts will I encounter if it is just the path that is being saved? Will I still be able to retrieve the image when I publish the system?

Thanks!

ABCDE
  • 131
  • 3
  • 6
  • 15
  • Your question is lacking a bit in the details department. If you publish your application and the sql server can still access the files at the path in the database it will be fine. What I might recommend is to store the file name in the images table instead of the full path. That allows more flexibility on the actual path. It can be in a config file or a separate table. – Sean Lange Nov 03 '16 at 13:29
  • Retrieving the image depends entirely where you are saving it and what permissions you have to that directory? This is a very broad question. – IronAces Nov 03 '16 at 13:31
  • 2
    There is a really good [answer by marc_s](http://stackoverflow.com/a/5613926/2882256) which refers to a Microsoft Research paper. Conclusion: avg image size <= 256K ? -> database, >= 1 MB ? -> File System, Between? -> It depends :) – Alex B. Nov 03 '16 at 13:58
  • 1
    You might want to look into FileStream and FileTable. – rheitzman Nov 03 '16 at 19:24

2 Answers2

1

Heres an article on how to store images in an image field within a SQL Server database:

Insert Picture into SQL Server 2005 Image Field using only SQL

And heres an interesting article on why / why not store images in a DB:

Insert Picture into SQL Server 2005 Image Field using only SQL

I would suggest keeping these seperate though and accessing the image on a file system by only storing the path to the image in the DB, unless the images are sensitive. Easier to encapsulate images in a DB but then space increases and so does cost.

Community
  • 1
  • 1
Sean H
  • 267
  • 2
  • 6
0

When saving the path to an object only, you are effectively disconnecting the object from the pointer to the object. So you can't use SQL to manage the lifecycle of the object and you would never be sure that the object exists on the file system till you tried to read it. If the object was stored within the database then you know it's present if the record is present.

There are many pros and cons to managing your objects inside or outside of the DB. You probably need to weigh up the estimated size of your objects.

Bill Karwin's SQL Antipatterns book has an excellent chapter on this exact design pattern.

G Davison
  • 1,079
  • 1
  • 14
  • 21