Wednesday, March 7, 2012

File storage in databases

I have written a few websites that host files and I have not been able to
resolve in my mind the issue of storing files in the file system vs. storing
them in the database as a blob and writing code to serve them into the web
stream. The latter approach got a lot easier with the dotnet framework, but
I still don't know if it is the most accepted approach.
The reason I like the idea of storing a file in SQL is that the file is
"bonded" to the rest of the record. (i.e. deletes, changes, etc. do not
require moving a file around). However, using regular files and storing
just the filename in the database makes retrieval of the files much more
straightforward for other applications that may need access to it without
using my usual web interface. Also, something inside me wants to say that
file systems should store files and databases should store data.
I know there is not a one-size-fits-all answer, but I would love to hear
anyone's comments.
Thanks!
-RyanRayn
There are lots of discussion about this issue on NG. Do some searching to
find out.
Personally, I prefer to store the file/s on the filesystem rather in the
database (the anme file just points to the actuall file on the disk)
As fas as I know by default SQL Server stores an IMAGE datatype in separate
pages but the table contains a pointer that points to the data page when
stored IMAGE datatype
For example, if these datatypes hold large quantities of data, and they were
stored in a table with the rest of the data, this would require SQL Server
to work harder when accessing the table. The larger the table, the more I/O
SQL Server has to perform in order to accomplish its tasks
Look at sp_tableoption 'tablename', 'text in row', 'on' in the BOL for more
details
"Ryan" <noones@.home> wrote in message
news:1170r48on54mb75@.corp.supernews.com...
> I have written a few websites that host files and I have not been able to
> resolve in my mind the issue of storing files in the file system vs.
storing
> them in the database as a blob and writing code to serve them into the web
> stream. The latter approach got a lot easier with the dotnet framework,
but
> I still don't know if it is the most accepted approach.
> The reason I like the idea of storing a file in SQL is that the file is
> "bonded" to the rest of the record. (i.e. deletes, changes, etc. do not
> require moving a file around). However, using regular files and storing
> just the filename in the database makes retrieval of the files much more
> straightforward for other applications that may need access to it without
> using my usual web interface. Also, something inside me wants to say that
> file systems should store files and databases should store data.
> I know there is not a one-size-fits-all answer, but I would love to hear
> anyone's comments.
> Thanks!
> -Ryan
>

No comments:

Post a Comment