The types TEXT
, NTEXT
and IMAGE
are obsolete - do not use them for new development. They will be removed from a future SQL Server version for good.
For SQL Server 2005 and up, use VARCHAR(MAX) / NVARCHAR(MAX)
if you're dealing with pure text files (like source code or CSV files), or VARBINARY(MAX)
if you're dealing with binary files.
Those allow up to 2 GB of storage for each single file, and you can use all the usual T-SQL string functions on them to manipulate them (the (N)VARCHAR(MAX) fields, that is).
If you're using SQL Server 2008, there's also an additional option - the FILESTREAM
attribute on VARBINARY(MAX)
columns. This allows you to store the files in the SQL Server machine's file system (instead of the database tables) while preserving transactional and data integrity.
FILESTREAM is recommended for files that are typically and usually larger than 1 MB in size, or if you ever need more than 2 GB (since you can't store more than 2 GB in a regular VARBINARY(MAX)
column).
Marc