1. 启用 SQL Server 2008 Filestream 功能
a. 开始/所有程序/SQL Server 2008/Configuration Tools/SQL Server Configuration
b. 选中Service,右键属性
c. 切换至Log On选项卡,设置如下图
d. 切换至FileStream选项卡,设置如下图
e. 点击OK结束设置
f. 在Management Studio中查看数据库的属性
2. 创建数据库和数据表
--Create Database CREATE DATABASE FSTtttt ON PRIMARY ( NAME = FSTtttt, FILENAME = 'E:\Database\FSTtttt.mdf' ), FILEGROUP FSG00001 CONTAINS FILESTREAM ( NAME = FSTtttt_fs, FILENAME = 'E:\Database\FSTtttt_fs' ) LOG ON ( NAME = FSTtttt_log, FILENAME = 'E:\Database\FSTtttt_log.ldf' ) GO USE [FSTtttt] GO --Create Table CREATE TABLE [dbo].[FSTest]( [Id] [uniqueidentifier] ROWGUIDCOL NOT NULL, [FileName] [nvarchar](64) NULL, [FileData] [varbinary](max) FILESTREAM NULL, UNIQUE NONCLUSTERED ( [Id] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] FILESTREAM_ON [FSG00001] GO
3. 注意事项
当数据库被备份一次之后,使用 Delete 无法删除对应的文件,这时可以修改数据库的恢复模式为简单(Simple),执行以下脚本即可
ALTER DATABASE FSTtttt SET RECOVERY SIMPLE GO CHECKPOINT GO ALTER DATABASE FSTtttt SET RECOVERY FULL GO
4. 示例下载
我的资源中存储读取图片的示例