SQL Server:如何存储二进制数据(例如 Word 文件)? [英] SQL Server: How to store binary data (e.g. Word file)?

查看:25
本文介绍了SQL Server:如何存储二进制数据(例如 Word 文件)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不是 DBA,所以我只是不知道使用各种方法在 SQL Server 中存储二进制数据的优缺点.

I'm not a DBA, so I just don't know the upsides and downsides of using various methods of storing binary data in an SQL Server.

  • varbinary(n) 仅存储 8000 个字节
  • varbinary(max) 存储 2 GB
  • BLOBs 适用于大文件,但带有管理"开销(文件仅在数据库中引用,但实际上位于本地硬盘上)
  • varbinary(n) stores only 8000 bytes
  • varbinary(max) stores 2 GB
  • BLOBs are meant for big files, but come with "administrative" overhead (the files being only referenced in the DB, but actually sitting on the local harddisk)

我基本上有大约 1000 个文档(每年),我想将它们存储在 SQL Server 2008 R2 数据库中(填充一个简单的 ASPX 表单上传,通过一个简单的 Gridview 和下载进行查看).所有文档可能大约为 2MB - 8MB(Word、Excel 文件).我猜测是我应该使用具有以下布局的表格MyDocuments:

I basically have about 1000 documents (per year) which I want to store in a SQL Server 2008 R2 database (being filled with a simple ASPX form upload, being viewed by a simple Gridview with download). All documents will probably be around 2MB - 8MB (Word, Excel files). My guess is that I should be using a table MyDocuments with the following layout:

MyDocuments 
    Data       varbinary(max)
    Title      varchar(255)
    ModifiedOn datetime()
    ModifiedBy varchar(100)

我在 varbinary(max) 上正常吗?还是我走错了方向(例如性能方面)?

Am I on track with varbinary(max)? Or am I going in the wrong direction (e.g. Performance-wise)?

推荐答案

SQL Server 2008 中有FILESTREAM"存储.它允许使用 SQL Server 2008 和 NTFS 文件系统的组合来存储和高效访问 BLOB 数据.

There is 'FILESTREAM' storage in SQL Server 2008. It allows storage of and efficient access to BLOB data using a combination of SQL Server 2008 and the NTFS file system.

你可以看看这些:

SQL Server 2008 中的 FILESTREAM 存储
使用 FileStream SQL Server 2008 保存和检索文件


小于 256K 的对象最好存储在数据库中,而大于 1M 的对象最好存储在文件系统中.


Objects smaller than 256K are best stored in a database while objects larger than 1M are best stored in the filesystem.

性能:Varbinary 与 FILESTREAM

Performance: Varbinary vs FILESTREAM

http://www.sqlskills.com/BLOGS/PAUL/post/SQL-Server-2008-FILESTREAM-performance.aspx
到 BLOB 还是不 BLOB:数据库或文件系统中的大对象存储
SQL Server 2008 FILESTREAM 性能

这篇关于SQL Server:如何存储二进制数据(例如 Word 文件)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆