Which data-type for storing images and documents in SQL Server 2005

后端 未结 4 419
逝去的感伤
逝去的感伤 2021-01-12 06:42

I must extend an existing .net-Application to store images and documents (mostly pdf\'s) in a SQL Server 2005 database.

Which SQL Server datatype is used best for s

相关标签:
4条回答
  • 2021-01-12 07:24

    VARBINARY or 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:

    http://msdn.microsoft.com/en-us/library/ms189087.aspx

    http://msdn.microsoft.com/en-us/library/ms186981.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)

    0 讨论(0)
  • 2021-01-12 07:35

    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.

    0 讨论(0)
  • 2021-01-12 07:37

    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.

    0 讨论(0)
  • 2021-01-12 07:38

    SQL Server 2005: Blobvarchar(max)
    SQL Server 2008: FileStream

    0 讨论(0)
提交回复
热议问题