How to Enable FILESTREAM on an Existing SQL Server Database

To be able to create a FILESTREAM enabled SQL Server Database or enable FILESTREAM on an existing SQL Server Database, you need to Enable FILESTREAM on the SQL Server instance.

To enable FILESTREAM on the existing database named Test_Database, run the following code:

ALTER DATABASE Test_Database
ADD FILEGROUP FileStreamFileGroup CONTAINS FILESTREAM
GO

ALTER DATABASE Test_Database
ADD FILE (NAME = FileStreamData, FILENAME = 'D:\Data\FileStreamData')
TO FILEGROUP FileStreamFileGroup
GO

The code will add FILESTREAM filegroup called FileStreamFileGroup to the database and create the FILESTREAM folder 'D:\Data\FileStreamData'.

The new 'D:\Data\FileStreamData' folder now contains an important system file filestream.hdr and an $FSLOG folder. Do not modify or delete the filestream.hdr file.

Before you run the ALTER DATABASE statement from this example, 'D:\Data\' folder must exist, where the FILESTREAM folder will be created (FILENAME refers to a path: 'D:\Data\FileStreamData' for a FILESTREAM filegroup). Folder 'D:\Data\FileStreamData' must not already exist when you execute the CREATE DATABASE statement.
If the last folder already exists, you will get the following error:

Msg 5170, Level 16, State 2, Line 2
Cannot create file 'D:\Data\FileStreamData' because it already exists. Change the file path or the file name, and retry the operation.

cannot_create_file_because_it_already_exists_filestream_alter