views:

48

answers:

4

What database field type should I use to store web pages (html, pdf, text) files in the same field? nvarchar(max)?

+2  A: 

Use VARBINARY(MAX). NVARCHAR is only for Unicode content, which won't handle PDFs well at all.

Marcelo Cantos
+1  A: 

You'd want to use VARBINARY(MAX) or NVARCHAR(MAX), depending on the type of data being stored and what you want to do with it. If you going to store files (which it sounds like, especially with mixed extensions), use VARBINARY(MAX). You can full-text index off that data type too -- although PDF's require an additional iFilter (at least it did with our SQL Server 2005 instance -- it may be there by default in 2008).

Keep in mind that you don't want to use IMAGE, as that data type (along with TEXT and NTEXT) is deprecated and is being removed in a future version of SQL Server. Here's the link about that.

Hope this helps.

David Hoerster
A: 

Would love to hear the requirements for the project that brought this project up.

Richard B
+1  A: 

VARBINARY(MAX). If you're using SQL Server 2008, then FILESTREAM is also an option that should be considered. According to Microsoft's guidelines, consider FILESTREAM when:

  • Objects that are being stored are, on average, larger than 1 MB.
  • Fast read access is important.
  • You are developing applications that use a middle tier for application
    logic.
Joe Stefanelli