_대문 | 방명록 | 최근글 | 홈피소개 | 주인놈
FrontPage › FileStreamAccess

Contents

[-]
1 언제 써먹나?
2 기본 설정
3 데이터베이스 생성하기
4 테이블 생성하기
5 FILESTREAM directory structure - where do the GUIDs come from?
6 참고자료


필자의 노트북에 설치된 버전이 영문 버전이다. 영어도 조낸 못하는 놈이 영문 버전 설치해 놓고 삽질한다. 그림이 짜증나도 이해하기 바란다.

1 언제 써먹나? #

도움말에는 다음과 같이 쓰여져 있다.

  • 데이터가 1MB를 넘을 때
  • 빠른 읽기를 요구할 때
  • 미들티어 어플리케이션의 개발 요구사항이 있을 때

딱히 와 닫지는 않아도 그러려니 하고 넘어가기를 바란다.

2 기본 설정 #

다음과 같이 기본 설정을 할 수 있다.

  1. SQL Server Configuration Manager 실행
  2. FileStream을 사용할 SQL Server 인스턴스를 찾아 마우스 오른 클릭 -> 속성
  3. FileStream 탭에서 허용할 만큼 체크를 하고 확인 클릭

file_stream01.jpg

다음으로 SSMS에서 다음과 같이 설정한다.
use master
go
exec sp_configure 'filestream access level', 2
go
reconfigure
go

마지막 매개변수는 다음과 같은 종류와 의미는 다음과 같다.

ValueDescription
0FILESTREAM support for the instance is Disabled
1FILESTREAM for Transact-SQL Access is Enabled
2FILESTREAM for Transact-SQL and Win32 streaming access is Enabled

나머지 기타사항은 도움말을 참고하기 바란다.

3 데이터베이스 생성하기 #

다음의 디렉토리를 생성 후 아래의 데이터베이스 생성 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.

만약 이런 메시지를 접하게 되면 이제까지의 과정 중 빠뜨린 부분이 있다는 뜻이 된다. 
*/

4 테이블 생성하기 #

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
file_stream02.jpg

5 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 

FileStreamData.jpg
0x6DBC7BFD 1바이트씩 짤라서 0x6D BC 7B FD 이므로 fd7bbc6d-... 과 같이 된다.


댓글 남기기..
이름: : 오른쪽의 새로고침을 클릭해 주세요. 새로고침
EditText : Print : Mobile : FindPage : DeletePage : LikePages : Powered by MoniWiki : Last modified 2018-04-13 23:12:52

조그만 친절이 한마디 사랑의 말이 저위의 하늘나라처럼 이 땅을 즐거운 곳으로 만든다.