New
Back
Database Management

Reliable database management for modern, high-performance systems.

Back
Data Modernisation

Reliable database management for modern, high-performance systems.

Back
Data Engineering

Reliable database management for modern, high-performance systems.

Back
Analytics & Intelligence

Reliable database management for modern, high-performance systems.

Back
Data Strategy Consulting

Reliable database management for modern, high-performance systems.

How to upload PDFs in to SQL Server

Thirunavukkarasu RM
Published on
April 1, 2021

Recently I came across the following question quite a few times, "is it possible to upload PDFs in to SQL Server?". So I planned to post this article which demonstrates how to upload PDFs in to SQL Server.

1. Enabling file stream feature in SQL Server

Go to SQL Server configuration manager and right click SQL Server service. Then we go to the filestream tab and enable file stream as shown below.

Once the changes are made, the SQL server needs to be restarted.

Once the filestream is enabled at the service level, the filestream needs to be enabled inside the SQL Server. Once the SQL Server is restarted, login to the server to enable file stream feature using the below syntax:

EXEC sp_configure filestream_access_level, 2

RECONFIGURE

2. Creating DEMO database

Create a new database with a name of your choice. I have named the DB as GeoPITS_DEMO as shown below.

Click Filegroups from the left pane to create a new filegroup for filestream. The following tab opens up on clicking 'FileGroups'.

Now, click on 'Add Filegroup' button under FILESTREAM section.

After setting a name for your Filegroup go to 'GENERAL' tab to create a new file. I have created a filestream of name 'FS'.

Add new file and choose File type as FILSTREAM Data.

3. Creating File Table

Now we are going to create a sample table in our database to upload all PDFs. But this time we are not going to create regular tables. Instead this type of table is called file table. Using file table, any documents or PDF or for that matter any file can be stored in the SQL Server. The created file tables can be found under the 'FileTables' section under 'Tables' in the left pane.

The following script can be used to create a new FileTable.

USE [GeoPITS_Demo] GO CREATE TABLE [dbo].[PDF_Storage] AS FILETABLE ON [PRIMARY] FILESTREAM_ON [FS]WITH(FILETABLE_DIRECTORY = N'FileTableDB', FILETABLE_COLLATE_FILENAME = Latin1_General_CI_AI)GO

After creating a new file table, simply right click on file table and select ExploreFileTable Directory.

This would open the network folder as shown below. Here we need to paste the copied PDF file.

After copying, to cross check if the files have been copied and loaded into the table, one could try to select all records from the table and fetch the PDF file information. The output can be seen as shown below.

So, the above steps enable us to upload PDF files into SQL Server. The same procedure can also be utilised to copy files of any format such as documents/video/audio into the SQL Server directly.

Further reading

If you found this article helpful, you might want to check out these related resources,

Thirunavukkarasu RM

Thirunavukkarasu Ramasamy has 17+ years of experience in database management and the Microsoft Data Platform, with expertise in SQL Server, database architecture, and data solutions. As the Senior Solution Architect of Geopits, he focuses on building scalable data platforms, modernizing database environments, and delivering reliable enterprise data solutions.

Our Latest Blogs

From monitoring to modernization, GeoPITS provides expert database management services that enhance performance, strengthen security, and reduce operational costs.

Ready to Transform Your Data?

Geopits works alongside your team as a strategic partner, starting with stabilizing your current databases, then modernizing your data infrastructure, and ultimately helping you unlock the full potential of AI.

170

Happy Clients so far

2100+

Databases Managed

142+

Successful Migrations

Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.