
To configure
FILE-STREAM in SQL Server, follow these steps.
FILE-STREAM allows you to store large binary data (like documents, images, videos) in the file system while maintaining transactional consistency with the database.
Step-by-Step: Enable and Configure
FILE-STREAM
1. Enable
FILE-STREAM
at the SQL Server Instance Level
- Open SQL Server Configuration Manager.
- Go to SQL Server Services.
- Right-click your SQL Server instance → Properties.
- Go to the
FILE-STREAM
- tab:
- Check Enable
FILE-STREAM
-
- for Transact-SQL access.
- Optionally check Enable
FILE-STREAM
-
- for file I/O streaming access.
- Provide a Windows share name (e.g., SQLFileStreamShare).
- Click Apply and restart the SQL Server service.
2. Enable
FILE-STREAM
Access at the Database Level
EXEC sp_configure 'filestream access level', 2;
RECONFIGURE;
The access level values are:
- 0 = Disabled
- 1 = T-SQL access only
- 2 = T-SQL and Win32 streaming access
3. Create a Database with
FILE-STREAM
CREATE DATABASE FileStreamDB
ON PRIMARY
(NAME = FileStreamDB_data, FILENAME = 'C:\SQLData\FileStreamDB.mdf'),
FILEGROUP FileStreamGroup CONTAINS
FILE-STREAM
(NAME = FileStreamDB_fs, FILENAME = 'C:\SQLData\FileStreamDB_fs')
LOG ON
(NAME = FileStreamDB_log, FILENAME = 'C:\SQLData\FileStreamDB.ldf');
GO
The
FILE-STREAM folder itself must not exist beforehand; SQL Server creates it. Its parent folder must exist.
4. Create a Table with
FILE-STREAM
Column
USE FileStreamDB;
GO
CREATE TABLE dbo.Documents
(
DocumentID UNIQUEIDENTIFIER ROWGUIDCOL NOT NULL UNIQUE DEFAULT NEWID(),
FileName NVARCHAR(260) NOT NULL,
FileData VARBINARY(MAX)
FILE-STREAM
NULL
);
GO
Note: The table must have a ROWGUIDCOL column with a unique constraint to support
FILE-STREAM.
Tips
FILE-STREAM
- is best for storing large objects (>1MB).
- It integrates with the NTFS file system for efficient storage and access.
- Backups include
FILE-STREAM
- data unless you exclude it explicitly.
For the full reference, see Microsoft’s
FILE-STREAM documentation.
From my SQL Server DBA handbook.