Which is the better practice to store file? Directly store the file in database or just the location to that file?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It depends. You need to consider several things.
If you have a mickey mouse freeware database, meaning that it does not handle blobs appropriately (reads the blobs on every
SELECT; does not store the blobs in a separate physical structure to the row; very slow with blobs; etc)If you have an enterprise SQL Platform, it is no problem at all to keep the blobs inside the database. In fact, retrieval is faster. These do not read the blobs on every
SELECT, they are stored in a separate physical structure to the rows. The one extra read to get the blob if theSELECTrequests it, is not a "performance problem".The
PAGESIZEin genuine SQL databases can be set as 2k; 4k; 8k; or 16k.The disadvantage of keeping the blobs in the database is, your database backups will be significantly larger.
The advantage of keeping the blobs in the database is:
data and referential integrity. You will not have the problem of having the rows that are out of synch with the blobs
the blobs are included in the backup: otherwise, upon a restore, the task of syncing the restored database with the restored files is a major problem.
I completed an assignment last year, where the customer had 130GB of data in the db, and 700GB of documents stored outside the db. After ten years of problems, they bit the bullet, and moved the documents into the db.
Guess what, what was supposed to be a simple job (long but simple, because the references were supposed to be absolutely correct), ended up being massive, because there were so many (a) duplicates, and (b) invalid references.
The resulting database was 630GB, there were 100GB of dupes. 2K pagesize.
Responses to Comments
Slash or Backslash
Easy.
IsWindozeindicator. It should be higher up in the table hierarchy, not at the level where theFilenameis located.Filenamecolumn, ifIsWindoze, change the slashes to backslashes.You will have a similar problem with the DriveLetter and colon
D:, which Unix does not have. Allow it only ifIsWindoze.