#title File Stream Access [[TableOfContents]] 필자의 노트북에 설치된 버전이 영문 버전이다. 영어도 조낸 못하는 놈이 영문 버전 설치해 놓고 삽질한다. 그림이 짜증나도 이해하기 바란다. ==== 언제 써먹나? ==== 도움말에는 다음과 같이 쓰여져 있다. * 데이터가 1MB를 넘을 때 * 빠른 읽기를 요구할 때 * 미들티어 어플리케이션의 개발 요구사항이 있을 때 딱히 와 닫지는 않아도 그러려니 하고 넘어가기를 바란다. ==== 기본 설정 ==== 다음과 같이 기본 설정을 할 수 있다. 1. SQL Server Configuration Manager 실행 1. FileStream을 사용할 SQL Server 인스턴스를 찾아 마우스 오른 클릭 -> 속성 1. FileStream 탭에서 허용할 만큼 체크를 하고 확인 클릭 attachment:file_stream01.jpg 다음으로 SSMS에서 다음과 같이 설정한다. {{{ use master go exec sp_configure 'filestream access level', 2 go reconfigure go }}} 마지막 매개변수는 다음과 같은 종류와 의미는 다음과 같다. ||Value||Description|| ||0||FILESTREAM support for the instance is Disabled|| ||1||FILESTREAM for Transact-SQL Access is Enabled|| ||2||FILESTREAM for Transact-SQL and Win32 streaming access is Enabled|| 나머지 기타사항은 도움말을 참고하기 바란다. ==== 데이터베이스 생성하기 ==== 다음의 디렉토리를 생성 후 아래의 데이터베이스 생성 Script를 실행한다. * c:\filestream (명령프롬프트에서 mkdir c:\filestream) {{{ use master go if exists (select name from sys.databases where name = 'filestreamdb') drop database filestreamdb go use master go create database filestreamdb on primary ( name = data01 , filename = 'c:\filestream\data01.mdf' ), filegroup filestream_fg contains filestream ( name = filestream_data01 , filename = 'c:\filestream' --요기를 주의해서 살펴봐라. c:\filestream\file 이 아니다. ) log on ( name = log01 , filename = 'c:\filestream\log01.ldf' ) /* 메시지 5591, 수준 16, 상태 1, 줄 1 FILESTREAM feature is disabled. 만약 이런 메시지를 접하게 되면 이제까지의 과정 중 빠뜨린 부분이 있다는 뜻이 된다. */ }}} ==== 테이블 생성하기 ==== {{{ use filestreamdb go create table dbo.filestreamtable ( fs_id uniqueidentifier rowguidcol not null unique, fsdata varbinary(max) filestream ); insert into filestreamtable values(newid(), cast ('inserting data into filestreamtable........' as varbinary(max))) go select fs_id , CONVERT(varchar(50), fsdata) fsdata from filestreamtable /* fs_id fsdata ------------------------------------ -------------------------------------------------- E1C9F831-7305-4C18-954A-5DFEFC5DD550 inserting data into filestreamtable........ */ declare @txcontext varbinary(max) begin transaction select @txcontext = get_filestream_transaction_context() print @txcontext commit --결과: 0x247E3F6CCDE6524FB5F20CA80003177B }}} attachment:file_stream02.jpg ==== FILESTREAM directory structure - where do the GUIDs come from? ==== {{{ SELECT o.name AS [Table], cp.name AS [Column], p.partition_number AS [Partition], r.rsguid AS [Rowset GUID], rs.colguid AS [Column GUID] FROM sys.sysrowsets r CROSS APPLY sys.sysrscols rs JOIN sys.partitions p ON rs.rsid = p.partition_id JOIN sys.objects o ON o.object_id = p.object_id JOIN sys.syscolpars cp ON cp.colid = rs.rscolid WHERE rs.colguid IS NOT NULL AND o.object_id = cp.id AND r.rsguid IS NOT NULL AND r.rowsetid = rs.rsid; GO }}} attachment:FileStreamData.jpg?width=100% 0x6DBC7BFD 1바이트씩 짤라서 0x6D BC 7B FD 이므로 fd7bbc6d-... 과 같이 된다. * [http://www.sqlskills.com/BLOGS/PAUL/post/FILESTREAM-directory-structure-where-do-the-GUIDs-come-from.aspx FILESTREAM directory structure - where do the GUIDs come from?] ==== 참고자료 ==== * [http://blogs.msdn.com/b/psssql/archive/2011/06/23/how-it-works-filestream-rsfx-garbage-collection.aspx How It Works: FileStream (RsFx) Garbage Collection] * [http://www.mssqltips.com/tip.asp?tip=1854 How to Backup and Restore a SQL Server FILESTREAM Enabled Database] * [http://www.mssqltips.com/tip.asp?tip=1850 Creating a SQL Server 2008 FILESTREAM Enabled Database and Using INSERT, UPDATE and DELETE statements to manage FILESTREAM Data] * [http://www.sqlservercentral.com/articles/FILESTREAM/67668/ FILESTREAM Setup and Testing without Visual Studio] * [http://searchsqlserver.techtarget.com/tip/0,289483,sid87_gci1356593_mem1,00.html Implementing SQL Server 2008 FILESTREAM functionalit] * [http://technet.microsoft.com/en-us/library/cc949109.aspx FILESTREAM Storage in SQL Server 2008] * [http://www.sqlservercentral.com/articles/SQL+Server+2008/66554/ Streaming Data Into SQL Server 2008 From an Application] * [http://blogs.msdn.com/psssql/archive/2009/05/06/how-to-use-filestream-feature-in-an-web-application-that-uses-forms-or-anonmous-authentication.aspx How to use FileStream feature in an ASP.NET Web Application that uses Forms or Anonymous authentication] * [http://msdn.microsoft.com/en-us/library/cc949109.aspx FILESTREAM Storage in SQL Server 2008] * [http://www.databasejournal.com/features/mssql/article.php/3802241/article.htm Working with FILESTREAM using VB.NET] * [http://www.sqlskills.com/BLOGS/PAUL/post/FILESTREAM-garbage-collection.aspx FILESTREAM garbage collection]