17.07.2015 Views

The Art of SQL Server FILESTREAM - Red Gate Software

The Art of SQL Server FILESTREAM - Red Gate Software

The Art of SQL Server FILESTREAM - Red Gate Software

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 1: Storing and Managing Unstructured DataEnter <strong>FILESTREAM</strong>By now it should be very clear that storing LOB data in the database <strong>of</strong>fers a number <strong>of</strong>benefits, but introduces performance challenges. Conversely, storing the LOB data in thefile system has overriding performance advantages, but fails to <strong>of</strong>fer some <strong>of</strong> the basicdata integrity, security, and manageability features that are required for business data,and which <strong>SQL</strong> <strong>Server</strong> provides.Up to now, most people have adopted file system storage by necessity, and <strong>of</strong>ten struggledto overcome the associated shortcomings. This is exactly where the new <strong>FILESTREAM</strong>feature fits in. <strong>FILESTREAM</strong> storage, introduced in <strong>SQL</strong> <strong>Server</strong> 2008, is implementedas an extension to the VARBINARY(MAX) data type. In other words, <strong>SQL</strong> <strong>Server</strong> implements<strong>FILESTREAM</strong> storage through VARBINARY(MAX) columns with an additional flagindicating that the BLOB data should be stored in the <strong>FILESTREAM</strong> data container. Itallows BLOBs to be stored in a special folder on the NTFS file system, while bringing thatdata under the transactional control <strong>of</strong> <strong>SQL</strong> <strong>Server</strong>. When a VARBINARY(MAX) column ismarked as a <strong>FILESTREAM</strong> column, the 2 GB storage limit <strong>SQL</strong> <strong>Server</strong> puts on large-valuetypes is no longer applicable.This new <strong>FILESTREAM</strong> attribute is only available on the VARBINARY(MAX) data type.It cannot be applied to the VARCHAR(MAX) data type. If you have large plain text valuesto store, you can opt to store them in a VARBINARY(MAX) <strong>FILESTREAM</strong> column anduse the CAST( AS VARCHAR(MAX)) method, if you need access to the plaintext data in a query. When accessing a CLOB stored in a <strong>FILESTREAM</strong> column usingthe <strong>FILESTREAM</strong> APIs (SqlFileStream managed class or the Win32 function,OpenSqlFileStream), you can use functions available in your programming language<strong>of</strong> choice to convert the byte stream to plain text. For this reason, from this point on, we'lluse the generic term "BLOB" to refer to all forms <strong>of</strong> LOB data.Note that, to access <strong>FILESTREAM</strong> data through the streaming API, you must connect to<strong>SQL</strong> <strong>Server</strong> using Integrated Security (Windows authentication). If you connect to <strong>SQL</strong>37

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!