.net 在 SQL Server 2005 中存储图像和文档的数据类型
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4598529/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Which data-type for storing images and documents in SQL Server 2005
提问by HCL
I must extend an existing .net-Application to store images and documents (mostly pdf's) in a SQL Server 2005 database.
我必须扩展现有的 .net-Application 以在 SQL Server 2005 数据库中存储图像和文档(主要是 pdf)。
Which SQL Server datatype is used best for saving these files and is it meaningfull to create a separate table that holds the fields, or is it no problem to put these fields directly in the "normal" business tables, as long as the select statements do not select them (or SELECT *).
哪种SQL Server数据类型最适合保存这些文件,创建一个单独的表来保存这些字段是否有意义,或者将这些字段直接放在“普通”业务表中是否没有问题,只要select语句做不选择它们(或选择 *)。
采纳答案by Cade Roux
VARBINARY or FILESTREAM
VARBINARY 或 FILESTREAM
No need to store them in a separate table - there are built-in controls you can use to force it to be stored in/out of row using sp_tableoption:
无需将它们存储在单独的表中 - 您可以使用内置控件强制使用 sp_tableoption 将它们存储在行内/行外:
http://msdn.microsoft.com/en-us/library/ms189087.aspx
http://msdn.microsoft.com/en-us/library/ms189087.aspx
http://msdn.microsoft.com/en-us/library/ms186981.aspx
http://msdn.microsoft.com/en-us/library/ms186981.aspx
http://www.microsoft.com/sqlserver/2008/en/us/wp-sql-2008-manage-unstructured.aspx
http://www.microsoft.com/sqlserver/2008/en/us/wp-sql-2008-manage-unstructured.aspx
(Note that there might be benefits to storing in a separate table if you are using different filegroups and backing them up independently or something like that - but that might be considered exceptional)
(请注意,如果您使用不同的文件组并独立备份它们或类似的东西,则存储在单独的表中可能会有好处 - 但这可能被认为是例外)
回答by Ta01
SQL Server 2005: Blobvarchar(max)
SQL Server 2008: FileStream
SQL Server 2005:Blobvarchar(max)
SQL Server 2008:FileStream
回答by XtremeBytes
Use varbinary(max) to store images and documents in sql server. I would recommend having them in a seperate table and not the main table by itself.
使用 varbinary(max) 在 sql server 中存储图像和文档。我建议将它们放在单独的表中,而不是单独放在主表中。
回答by Jamie Treworgy
To answer the other part of your question, if you are storing binary data in a database, don't mix the data in a table with other fields. You probably won't be doing any searching or indexing on the binary data, and access to any metadata will be slowed down by the size of the table. Keep just the images/files in a separate table.
要回答问题的另一部分,如果您将二进制数据存储在数据库中,请不要将表中的数据与其他字段混合。您可能不会对二进制数据进行任何搜索或索引,并且对任何元数据的访问都会因表的大小而变慢。仅将图像/文件保存在单独的表格中。
Though I can think of good reasons to keep files in a SQL server database (for example: not a web app), what @JonH says as well: keep them in the file system unless you have a compelling reason not to.
虽然我可以想到将文件保存在 SQL 服务器数据库中的充分理由(例如:不是 Web 应用程序),@JonH 也说:将它们保存在文件系统中,除非您有令人信服的理由不这样做。

