代码如下:
EXEC sp_configure filestream_access_level, 2
RECONFIGURE
3.创建支持FileStream 的数据库
代码如下:
[sql]
CREATE DATABASE test
ON
( NAME = test_dat,
FILENAME = 'C:Program FilesMicrosoft SQL ServerMSSQL11.MSSQLSERVERMSSQLDATAtestdat.mdf' ),
FILEGROUP testGroup1 CONTAINS FILESTREAM
( NAME = testgroup_dat ,
FILENAME = 'C:Program FilesMicrosoft SQL ServerMSSQL11.MSSQLSERVERMSSQLDATAtestGroup1.ndf')
LOG ON
( NAME = Sales_log,
FILENAME = 'C:Program FilesMicrosoft SQL ServerMSSQL11.MSSQLSERVERMSSQLDATAtestlog.ldf' ) ;
当然你也可以用以下脚本,在已存在的数据库添加一个文件组用于支持FileStream.
代码如下:
[sql]
ALTER database test
ADD FILEGROUP FileStreamRecord
CONTAINS FILESTREAM
GO
--Add a file for storing database photos to FILEGROUP
ALTER database test
ADD FILE
(
NAME= 'FileStreamRecord',
FILENAME = 'D:Program FilesMicrosoft SQL ServerMSSQL11.MSSQLSERVERMSSQLDATATestFileStreamRecord.ndf'
)
TO FILEGROUP FileStreamRecord
GO
4. 创建可以存储FileStream 的数据表
代码如下:
CREATE TABLE FileStreamRecording
[sql]
(
ID int,
RowGuidColumn UNIQUEIDENTIFIER
NOT NULL UNIQUE ROWGUIDCOL,
FILESTREAMColumn varbinary(MAX) FILESTREAM
);
[sql]
[sql]
5.使用
代码如下:
[sql]
INSERT INTO FileStreamRecording VALUES(1, NEWID(), 0x00);
INSERT INTO FileStreamRecording VALUES(2, NEWID(), 0x00);
INSERT INTO FileStreamRecording VALUES(3, NEWID(), 0x00);
GO
SELECT FILESTREAMColumn.PathName() AS 'PathName' FROM FileStreamRecording;
具体的使用可参考联机帮助或在线帮助。