Store audio in SQL Server?

2019-08-01 11:34发布

Is it a good idea to store audio files (mp3, wav) in SQL Server as BLOBs? One of the merits appears to be saving Hard disk space. Does this have any impact on scalability or performance?

4条回答
疯言疯语
2楼-- · 2019-08-01 12:11

No, it's not a good idea :) Variable-sized fields (such as TEXT and BLOB) have all sorts of performance impacts. A better approach is store the files on disk and just maintain a reference to them in a DB table. Nowadays, hard drive space is so cheap (especially compared to CPU and I/O performance) that it shouldn't even be a concern.

查看更多
够拽才男人
3楼-- · 2019-08-01 12:12

If you are using Sql Server 2008 you can use the filestream attribute. Sql Server will store the file on the file system but link it to a varbinary column.

Check out the link below:

http://www.aghausman.net/sql_server/configure-sql-server-2008-for-file-stream-2.html (Broken link - still accessible via Internet Archive at https://web.archive.org/web/20120530062012/http://www.aghausman.net/sql_server/configure-sql-server-2008-for-file-stream-2.html)

查看更多
萌系小妹纸
4楼-- · 2019-08-01 12:13

I think it depends a lot on how your application is designed. If you are going to be retrieving the audio files often (or updating them) it could be a serious performance hit as the audio files can be quite large. Why wouldn't you put them on a shared network location instead and just store the path to the file in the database? Hard drive space is cheap, bandwidth and SQL performance isn't. Unless you have a very good reason to keep them in the database (and I don't think saving hard drive space is it) you are better off storing them locally or on a shared path.

查看更多
地球回转人心会变
5楼-- · 2019-08-01 12:20

If you have the option of upgrading to SQL 2008 (i.e. if you're licensed for free upgrades) then FILESTREAM is the best choice - it puts "links" in the column but uses the regular file system to actually store the data.

In SQL 2005 or earlier, I wouldn't do it. I fail to see how it's going to save hard disk space, either; 5 megs is 5 megs whether it's a file on disk or sitting in a database column somewhere; the latter just makes it harder to get to, and as others have mentioned can have a negative effect on your overall DB performance. I guess there's some minor file system overhead like minimum cluster sizes, but for large files (especially audio) the effect is negligible.

查看更多
登录 后发表回答