100 likes | 299 Views
Filestream Data Storage. Filestream storage. Storing large binary objects in databases is suboptimal Large objects take buffers in database memory Updating large objects cause database fragmentation In file system however, "update" is delete and insert
E N D
Filestream storage • Storing large binary objects in databases is suboptimal • Large objects take buffers in database memory • Updating large objects cause database fragmentation • In file system however, "update" is delete and insert • "Before image" in an update is not deleted immediately • Storing all related data in a database adds • Transactional consistency • Integrated, point-in-time backup and restore • Single storage and query vehicle
Filestream Implementation • A filegroup for filestream storage is declared using DDL • Filestream storage is tied to a database • The filegroup is mapped to a directory • Must be NTFS file system • Caution: Files deleteable from file system if you have appropriate permissions • VARBINARY(MAX) columns can be defined with FILESTREAM attribute • Table must also have UNIQUEIDENTIFIER column • Filestream storage not available for other large types • Data is stored in the file system
Programming with Filestreams • Filestream columns are available with SQL methods • If SQL is used, indistinguishable from varbinary(max) • Filestream can be accessed and modified using file IO • PathName function retrieves a symbolic path name • Acquire context with • GET_FILESTREAM_TRANSACTION_CONTEXT • Use OpenSqlFilestream to get a file handle based on • File Name • Required Access • Access Options • FilestreamTransaction context
Filestream demo
Filestream behaviors • Streaming programming model available using • System.Data.SqlTypes.SqlFileStream - .NET • OpenSqlFilestream – SQL Native Client • Also available using a PInvoke wrapper with .NET • Streaming supported with ReadCommitted isolation level • File is required for handle, so to insert • Insert a zero-length value • Retrieve path and transaction context • Write using streamed IO
Review • SQL Server stores relational and non-relational data • Filestream storage stores BLOBs on file system • Buffer, fragmentation savings • Accessed using File IO • Best of both worlds: • Transactional consistency • Integrated, point-in-time backup and restore • Single storage and query vehicle • NTFS benefits • High-performance Win32 streaming
Resources • Whitepaper: Managing Unstructured Data with SQL Server 2008 http://www.microsoft.com/sql/techinfo/whitepapers/sql_2008_unstructured.mspx
© 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.