Working with Filetable to upload documents into SQL Server

By | November 13, 2018

A simple script on how to setup and work with file tables in MS SQL Server. This basically does the bare minimum to setup and create filetables in SQL Server and allows users to directly upload files into the directory and see them reflect inside of SQL Server.

CREATE DATABASE MyFileTable
GO
WITH FILESTREAM
( 
NON_TRANSACTED_ACCESS = FULL,
DIRECTORY_NAME = N'FileTableDir'
);
GO
/* Add a FileGroup that can be used for FILESTREAM */
ALTER DATABASE MyFileTable
ADD FILEGROUP FileTableFG
CONTAINS FILESTREAM;
GO
/* Add the folder that needs to be used for the FILESTREAM filegroup. */
ALTER DATABASE MyFileTable
ADD FILE
(
NAME= 'FileTable_File',
FILENAME = 'C:\Work\FileTable'
)
TO FILEGROUP FileTableFG;
GO
USE MyFileTable;
GO
/* Create a FileTable */
CREATE TABLE resumes AS FILETABLE
WITH
( 
FILETABLE_DIRECTORY = 'FileTableDir'
);
GO