You are on page 1of 28

Module 16

Storing and Querying BLOBs and


Text Documents in SQL Server
Module Overview

Considerations for BLOB Data


Working with FILESTREAM
• Using Full-Text Search
Lesson 1: Considerations for BLOB Data

What Are BLOBs?


Storing BLOBs in the Database
Storing BLOBs on the File System
FILESTREAM
FileTables
• Demonstration: BLOBs in the Adventure Works
Database
What Are BLOBs?

• Technical challenges presented by BLOBs


• Storage and management costs
• Security
• Indexing and searching text data
• Referential and transactional integrity

• BLOB storage strategies


• In the database
• In the file system
• FILESTREAM
• FileTable
• Remote BLOB storage
Storing BLOBs in the Database

• Storing BLOBs in the database


• Varbinary(max)—2 GB max size
• 8,000 bytes or less is stored in the same data page
• Larger than 8,000 byes is stored in separate data pages
• Use sp_tableoption—large value types out of row

• Advantages
• Everything within the database for backups, restores,
transactional and referential integrity, and so on
• Disadvantages
• BLOBs can only be accessed through Transact-SQL
• Large BLOBs can reduce performance
Storing BLOBs on the File System

• Storing BLOBs on the file system


• BLOBs stored outside the database
• Store a path to the BLOB

• Two data stores


• Maintaining data integrity in two places
• Advantages
• Requires little configuration to store large files
• Better performance, and reduced fragmentation

• Disadvantages
• No mechanism for keeping data in step
• Security must be configured for the file system
FILESTREAM

• FILESTREAM implementation
• Varbinary(max) column
• BLOBs stored in NTFS file system
• Create a FILESTREAM filegroup

• Advantages
• Better performance for BLOBs > 1 MB and no limit
• Fully integrated: management, security, referential and
transactional integrity
• Full text searches

• Disadvantages
• Applications cannot access BLOBs directly
• Must be stored on hard disk or SAN
FileTables

• FileTable implementation
• An extension to FILESTREAM
• Varchar(max) column with FILESTREAM enabled
• Can use a shared folder on a remote server

• FileTable benefits
• Applications can read and manipulate BLOB content
• Advantages
• All the advantages of FILESTREAM, plus applications
such as Word and Excel can access files
• Can read, write and delete

• Disadvantages
• Separate database table with fixed schema
Demonstration: BLOBs in the Adventure Works
Database

In this demonstration, you will see how a database


stores BLOBs
Lesson 2: Working with FILESTREAM

Considerations for Using FILESTREAM


Enabling FILESTREAM
Considerations for Using FileTables
Enabling FileTables
FILESTREAM Access
• Demonstration: Configuring FILESTREAM and
FileTables
Considerations for Using FILESTREAM

• Each table that uses FILESTREAM columns must contain a


uniqueidentifier ROWGUID column
• A FILESTREAM filegroup is required
• For best performance, the filegroup should be physically
separated from other important files
• FILESTREAM BLOBs are backed up and restored with the
database
• Small BLOBs may perform better without FILESTREAM
enabled
• FILESTREAM is not compatible with database mirroring
• Transparent encryption does not protect FILESTREAM
BLOBs
• FILESTREAM is not supported by Always Encrypted
Enabling FILESTREAM

• Enable FILESTREAM for the instance


• EXEC sp-configure filestream_access_level, 2
RECONFIGURE
• Create a FILESTREAM filegroup for the database
• Create a table with a FILESTREAM column
Considerations for Using FileTables

• FileTable prerequisites
• FILESTREAM enabled
• FILESTREAM filegroup configured
• Nontransactional access configured
• FileTable directory configured

• FileTable limitations
• No table partitioning
• No database replication
• No transactional rollbacks and point-in-time recovery
• Limited access to FileTables after AlwaysOn availability
group failover
• No DML INSTEAD OF triggers
• No indexed views for FileTables
Enabling FileTables

• Enabling Nontransactional Access


• Configuring a Directory for FileTables
• CREATE DATABASE HumanResources
WITH FILESTREAM ( NON_TRANSACTED_ACCESS= FULL,
DIRECTORY_NAME = N'FileTableDirectory');
FILESTREAM Access

• Find the file system paths, and IDs FILESTREAM


and FileTable folders
• PathName()
• File TableRootPath()
• GetFileNamespacePath()
Demonstration: Configuring FILESTREAM and
FileTables

In this demonstration, you will see how to enable


and create FILESTREAM columns and FileTables
Lesson 3: Using Full-Text Search

What is Full-Text Search?


Components and Architecture of Full-Text Search
Configuring Full-Text Search
Querying a Full-Text Index
Demonstration: Configuring and Using Full-Text
Search
• Enabling and Using Semantic Search
What is Full-Text Search?

• Types of Full-Text Search


• Simple term search
• Prefix term search
• Generation term search
• Proximity term search
• Thesaurus search
• Weighted term search

• Performance
• Property-scoped Searches
• Language Support
Components and Architecture of Full-Text
Search
Configuring Full-Text Search

• Considerations for Full-Text Search


• Data types: char, varchar, nchar, nvarchar, text, ntext,
image, xml, varbinary, varbinary(max), incl FILESTREAM
• Requires a unique, non-null column, ideally integer
• One full-text index per table
• Specify language for each column in the index
• Consider dedicated filegroup for full-text indexes
• Consider off-peak crawls to update the index

• Create a full-text catalog


• Create a full-text index
Querying a Full-Text Index

• CONTAINS and FREETEXT


• Returns TRUE or FALSE
• Use them to find matches
• Specify one or more columns

• CONTAINSTABLE and FREETEXTTABLE


• Returns a table
• Tables can then be references from a SELECT statement
• Contains a KEY and RANK column

• Using a NEAR Proximity Term


• Search for rows that contain two words or phrases
close to each other
Demonstration: Configuring and Using Full-Text
Search

In this demonstration, you will see how to create a


full-text index and use it for generation term
searches
Enabling and Using Semantic Search

• Semantic search extends full-text search


• Identify similar or related documents

• Enabling semantic search functionality


• Installing the Semantic Language Statistic database
• Adding semantic search to a full-text index

• Using semantic search functions in queries


• SEMANTICKEYPHRASETABLE
• SEMANTICSIMILARITYTABLE
• SEMANTICSIMILARITYDETAILSTABLE
Lab: Storing and Querying BLOBs and Text
Documents in SQL Server

Exercise 1: Enabling and Using FILESTREAM


Columns
Exercise 2: Enabling and Using FileTables
• Exercise 3: Using a Full-Text Index

Logon Information
Virtual machine: 20762C-MIA-SQL
User name: ADVENTUREWORKS\Student
Password: Pa55w.rd

Estimated Time: 45 minutes


Lab Scenario

You manager has asked you to evaluate and optimize the


performance of queries against the LargePhoto column in
the Production.ProductPhotos table. You have decided
that, because BLOBs in this column are often larger than
1 MB, it will be advantageous to create a FILESTREAM
column and move the existing data into the new column.
You have also been asked to create a FileTable, with a
corresponding shared folder, so users can store
documents by using Word and other desktop applications.
These files will be accessible through the file share and
database queries.
Lab Scenario (Continued)

Finally, you have also been asked to create a full-


text index on the Description column in the
Production.ProductDescriptions table so that
generation term queries and thesaurus queries can
be used.
Lab Review

How did the results of the simple term query you


executed in Exercise 3, Task 2 differ from the results
of the generation terms query?
• What did you notice about the results of the third
query you ran against the full-text index?
Module Review and Takeaways

• In this module, you have seen the different


approaches database administrators can take to
the storage of BLOBs, such as images, documents,
and videos. You have learned how to enable and
use the advance FILESTREAM technology and
FileTables for BLOBs. You have also learned how
to configure and use File-Text Search.

You might also like