This article will discuss SQL Server FILESTREAM including installation, configuration, enabling and general considerations.

本文将讨论SQL Server FILESTREAM,包括安装,配置,启用和一般注意事项。

We may need to store a different kind of data in our SQL Server database apart from the regular table-based data. This data may be in multiple forms such as a document, images, audio or video files. You might have seen people using BLOB data to store these kinds of data, but you can save only up to 2 GB using this. This kind of data also slow down the performance of your database system since it tends to be large and takes significant system resources to bring it back from the disk.

除了基于常规表的数据外,我们可能需要在SQL Server数据库中存储另一种数据。 该数据可以采用多种形式,例如文档,图像,音频或视频文件。 您可能已经看到人们使用BLOB数据来存储此类数据,但是使用此数据最多只能保存2 GB。 这类数据通常会很大,并且会占用大量系统资源才能将其从磁盘中恢复,因此也会降低数据库系统的性能。

FILESTREAM, in SQL Server, allows storing these large documents, images or files onto the file system itself. In FILESTREAM, we do not have a limit of storage up to 2 GB, unlike the BLOB data type. We can store large size documents as per the underlying file system limitation. SQL Server or other applications can access these files using the NTFS streaming API. Therefore, we get the performance benefit of this streaming API as well while accessing these documents.

SQL Server中的FILESTREAM允许将这些大文档,图像或文件存储到文件系统本身。 在文件流中,与BLOB数据类型不同,我们没有最大2 GB的存储限制。 我们可以根据基本文件系统限制存储大尺寸文档。 SQL Server或其他应用程序可以使用NTFS流API来访问这些文件。 因此,在访问这些文档时,我们还将获得此流API的性能优势。

Note: FILESTREAM is not a SQL Server data type to store data

注意: FILESTREAM不是用于存储数据SQL Server数据类型

Traditionally if we store the data in the BLOB data type, it is stored in the Primary file group only. In SQL Server FILESTREAM, We need to define a new filegroup ‘FILESTREAM’. We need to define a table having varbinary(max) column with the FILESTREAM attribute. It allows SQL Server to store the data in the file system for these data type. When we access the documents that are stored in the file system using the FILESTREAM, we do not notice any changes in accessing it. It looks similar to the data stored in a traditional database.

传统上,如果我们将数据存储为BLOB数据类型,则仅将其存储在主文件组中。 在SQL Server FILESTREAM中,我们需要定义一个新的文件组'FILESTREAM'。 我们需要使用FILESTREAM属性定义一个具有varbinary(max)列的表。 它允许SQL Server将这些数据类型的数据存储在文件系统中。 当我们使用FILESTREAM访问存储在文件系统中的文档时,我们在访问文件时没有发现任何更改。 它看起来类似于存储在传统数据库中的数据。

Let us understand the difference in storing the images in the database or the file system using SQL Server FILESTREAM.

让我们了解使用SQL Server FILESTREAM将图像存储在数据库或文件系统中的区别。

Below you can traditional database storing the employee photo in the database itself.

您可以在下面的传统数据库中将员工照片存储在数据库本身中。

Now let us look at the changes in this example using the SQL Server FILESTREAM feature.

现在,让我们使用SQL Server FILESTREAM功能查看此示例中的更改。

In the above illustration, you can see the documents are stored in the file system, and the database has a particular filegroup ‘FILESTREAM’. You can perform actions on the documents using the SQL Server database itself.

在上图中,您可以看到文档存储在文件系统中,并且数据库具有特定的文件组“ FILESTREAM”。 您可以使用SQL Server数据库本身对文档执行操作。

One more advantage of the FILESTREAM is that it does not use the buffer pool memory for caching these objects. If we cache these large objects in the SQL Server memory, it will cause issues for normal database processing. Therefore, FILESTREAM provides caching at the system cache providing performance benefits without affecting core SQL Server performance.

FILESTREAM的另一个优点是它不使用缓冲池内存来缓存这些对象。 如果我们将这些大对象缓存在SQL Server内存中,则将导致正常的数据库处理问题。 因此,FILESTREAM在系统缓存中提供缓存,从而在不影响核心SQL Server性能的情况下提供了性能优势。

在SQL Server中启用FILESTREAM功能 (Enabling the FILESTREAM feature in SQL Server)

We can enable the FILESTREAM feature differently in SQL Server.

我们可以在SQL Server中以其他方式启用FILESTREAM功能。

  1. During Installation: You can configure FILESTREAM during the SQL Server installation. However, I do not recommend doing it during the installation because we can later enable it as per our requirements 在安装期间:您可以在SQL Server安装期间配置FILESTREAM。 但是,我不建议在安装过程中这样做,因为以后我们可以根据需要启用它
  2. In the SQL Server properties, you can see a tab ‘FILESTREAM’.

    在SQL Server属性中,可以看到“ FILESTREAM”选项卡。

    Click on ‘FILESTREAM’, and you get below screen. Here you can see that this feature is not enabled by default

    点击“ FILESTREAM”,您将得到以下屏幕。 在这里您可以看到默认情况下未启用此功能

  • Put a tick in the checkbox ‘Enable FILESTREAM for Transact-SQL access’ 在复选框“为Transact-SQL访问启用文件流”复选框中打勾
  • We can also enable the read\write access from the windows for file I/O access. Put a tick on the ‘Enable FILESTREAM for file I/O access’ as well 我们还可以从窗口启用对文件I / O访问的读写访问权限。 还要在“为文件I / O访问启用FILESTREAM”上打勾
  • Click Apply to activate the FILESTREAM feature in SQL Server. You will get a prompt to restart the SQL Server service. Once we have enabled FILESTREAM access and restarted SQL Server, we also need to specify the access level using SSMS. We need to make changes in sp_configure to apply this setting.

    单击“ 应用”以激活SQL Server中的FILESTREAM功能。 您将看到提示重新启动SQL Server服务。 启用FILESTREAM访问并重新启动SQL Server之后,我们还需要使用SSMS指定访问级别。 我们需要在sp_configure中进行更改以应用此设置。

Run the below command to show the advanced option in sp_configure.

运行以下命令以显示sp_configure中的高级选项。

USE masterGoEXEC sp_configure 'show advanced options'Go

Run the command sp_configure to check all available options. We can see all the available options now. Since we are interested in FILESTREAM only, I highlighted this particular option.

运行命令sp_configure以检查所有可用选项。 我们现在可以看到所有可用的选项。 由于我们仅对FILESTREAM感兴趣,因此我强调了此特定选项。

Below is the option in the sp_configure

以下是sp_configure中的选项

Option

Min value

Max Value

Filestream access level

0

2

选项

最低价值

最大值

文件流访问级别

0

2

We need to specify the value from 0 to 2 while enabling SQL Server FILESTREAM using the query.

在使用查询启用SQL Server FILESTREAM时,我们需要指定0到2之间的值。

FILESTEAM access level

Description

0

Value 0 shows that FILESTREAM access is disabled for this

1

Value 1 enables the FILESTREAM access for the SQL query.

2

Value 2 enables the FILESTREAM access for the SQL query and Windows streaming.

FILESTEAM访问级别

描述

0

值0表示为此禁用了FILESTREAM访问

1个

值1启用SQL查询的FILESTREAM访问。

2

值2启用对SQL查询和Windows流的FILESTREAM访问。

You can run the command to specify the access level. In below command, you can see that we have specified SQL Server FILESTREAM access level as 2.

您可以运行命令来指定访问级别。 在下面的命令中,您可以看到我们已将SQL Server FILESTREAM访问级别指定为2。

EXEC sp_configure filestream_access_level, 2GORECONFIGURE WITH OVERRIDEGO

If you do not enable FILESTREAM using the SQL Server Configuration Manager, You can get the error message

如果未使用SQL Server配置管理器启用FILESTREAM,则可能会收到错误消息

‘FILESTREAM feature could not be initialized. The operating system Administrator must enable FILESTREAM on the instance using Configuration Manager.’

'FILESTREAM功能无法初始化。 操作系统管理员必须使用Configuration Manager在实例上启用FILESTREAM。

We can also provide this access level using the SSMS. Right click on the server instance and go to properties.

我们还可以使用SSMS提供此访问级别。 右键单击服务器实例,然后转到属性。

Now click on Advanced, and you can see a separate group for SQL Server FILESTREAM.

现在,单击Advanced ,您将看到一个单独SQL Server FILESTREAM组。

In this group, we can define the SQL Server FILESTREAM access level from the drop-down option as shown below.

在该组中,我们可以从下拉选项中定义SQL Server FILESTREAM访问级别,如下所示。

In this GUI mode, we have three options listed. The following table shows the mapping between GUI and t-SQL options for SQL Server FILESTREAM access level.

在此GUI模式下,我们列出了三个选项。 下表显示了SQL Server FILESTREAM访问级别的GUI和t-SQL选项之间的映射。

GUI Option

Equivalent t-SQL option

Description

Disabled

EXEC sp_configure filestream_access_level, 0

Disable access

Trasact-SQL access enabled

EXEC sp_configure filestream_access_level, 1

Access for t-SQL only

Full access enabled

EXEC sp_configure filestream_access_level, 2

Full access (t-SQL and windows streaming)

GUI选项

等效的t-SQL选项

描述

残障人士

EXEC sp_configure filestream_access_level,0

禁用访问

启用Trasact-SQL访问

EXEC sp_configure filestream_access_level,1

仅适用于t-SQL

启用完全访问

EXEC sp_configure filestream_access_level,2

完全访问权限(t-SQL和Windows流)

使用SQL Server FILESTREAM功能时要考虑的重要点 (Important points to consider while using the SQL Server FILESTREAM feature)

  • We can use the SELECT, INSERT, UPDATE, and DELETE statements similar to a standard database query in FILESTREAM 我们可以使用SELECT,INSERT,UPDATE和DELETE语句,类似于FILESTREAM中的标准数据库查询
  • We should use FILESTREAM if the object size is larger than 1 MB on average 如果对象大小平均大于1 MB,则应使用FILESTREAM
  • Each row should have a unique row ID to use this functionality, and it should not contain NULL values 每行应具有唯一的行ID才能使用此功能,并且不应包含NULL值
  • We can create the FILESTREAM filegroup on the compressed volume as well 我们也可以在压缩卷上创建FILESTREAM文件组
  • In the Failover clustering, we need to use a shared disk for the FILESTREAM filegroup 在故障转移群集中,我们需要将共享磁盘用于FILESTREAM文件组
  • We can add multiple data containers in the FILESTREAM filegroup 我们可以在FILESTREAM文件组中添加多个数据容器
  • We cannot encrypt FILESTREAM data 我们无法加密FILESTREAM数据
  • You cannot use SQL logins with the FILESTREAM container 您不能将SQL登录名与FILESTREAM容器一起使用

结论: ( Conclusion: )

In this article, we took the overview the FILESTREAM feature in SQL Server and explored ways to enable it at the SQL Server instance level. In the next article, we will create a database with SQL Server FILESTREAM data and perform multiple operations on it.

在本文中,我们概述了SQL Server中的FILESTREAM功能,并探讨了在SQL Server实例级别启用该功能的方法。 在下一篇文章中,我们将创建一个包含SQL Server FILESTREAM数据的数据库,并对它执行多项操作。

目录 (Table of contents)

FILESTREAM in SQL Server
Managing data with SQL Server FILESTREAM tables
SQL Server FILESTREAM Database backup overview
Restoring a SQL Server FILESTREAM enabled database
SQL Server FILESTREAM database recovery scenarios
Working with SQL Server FILESTREAM – Adding columns and moving databases
SQL Server FILESTREAM internals overview
Importing SQL Server FILESTREAM data with SSIS packages
SQL Server FILESTREAM queries and Filegroups
Viewing SQL Server FILESTREAM data with SSRS
SQL Server FILESTREAM Database Corruption and Remediation
Export SQL Server FILESTREAM Objects with PowerShell and SSIS
SQL FILESTREAM and SQL Server Full Text search
SQL Server FILESTREAM and Replication
SQL Server FILESTREAM with Change Data Capture
Transaction log backups in a SQL FILESTREAM database
SQL FILESTREAM Compatibility with Database Snapshot, Mirroring, TDE and Log Shipping
SQL Server FILETABLE – the next generation of SQL FILESTREAM
Managing Data in SQL Server FILETABLEs
SQL Server FILETABLE Use Cases
SQL Server中的文件流
使用SQL Server FILESTREAM表管理数据
SQL Server FILESTREAM数据库备份概述
还原启用了SQL Server FILESTREAM的数据库
SQL Server FILESTREAM数据库恢复方案
使用SQL Server FILESTREAM –添加列和移动数据库
SQL Server FILESTREAM内部概述
使用SSIS包导入SQL Server FILESTREAM数据
SQL Server FILESTREAM查询和文件组
使用SSRS查看SQL Server FILESTREAM数据
SQL Server FILESTREAM数据库损坏和修复
使用PowerShell和SSIS导出SQL Server FILESTREAM对象
SQL FILESTREAM和SQL Server全文搜索
SQL Server FILESTREAM和复制
具有更改数据捕获功能SQL Server FILESTREAM
SQL FILESTREAM数据库中的事务日志备份
SQL FILESTREAM与数据库快照,镜像,TDE和日志传送的兼容性
SQL Server FILETABLE –下一代SQL FILESTREAM
在SQL Server FILETABLEs中管理数据
SQL Server FILETABLE用例

翻译自: https://www.sqlshack.com/filestream-in-sql-server/

SQL Server中的文件流相关推荐

  1. 记一次从Sql Server中图片二进制流还原回图片的开发过程

    背景:最近在客户现场做项目上线时,需要数据迁移工作.客户之前用的一个BS桌面应用,其中关于图片的存储全部以二进制流的方式写入到Sql Server数据库表中的某个字段中,如下图所示,由于新开发应用采用 ...

  2. 转储sql文件_在Linux上SQL Server中更改SQL转储文件位置

    转储sql文件 In this article, we will talk about SQL Dump files and the process to change the dump direct ...

  3. SQL Server中的即时文件初始化概述

    This article gives an overview of Instant File Initialization and its benefits for SQL Server databa ...

  4. 在SQL Server中保存和输出任意类型的文件

    我们可以把任意类型的文件保存到SQL Server中,在进行例子之前,先建立测试用表格,TestFile.sql: if exists (select * from dbo.sysobjects wh ...

  5. SQL Server中读取XML文件的简单做法

    SQL Server 2000使得以XML导出数据变得更加简单,但在SQL Server 2000中导入XML数据并对其进行处理则有些麻烦.本文介绍在SQL Server中读取XML文件的简单做法. ...

  6. 使用T-SQL导入多个文件数据到SQL Server中一文的疑惑

    - 今天,由于毕业论文需要,我想弄数据转换,所以看了一看T-SQL,oracle实在没时间去学,好在SQL我还是很熟悉,所以打算看一看,写一些存储过程来完成任务. 我无意中在csdn上找到这样一篇文章 ...

  7. 在SQL Server中导入和使用CSV文件

    介绍 (Introduction) CSV (comma separated values) is one of the most popular formats for datasets used ...

  8. SQL Server中的数据库文件组和零碎还原

    So far, we discussed many de-facto details about SQL Server database backup and restore. In this 15t ...

  9. sql数据库备份默认路径_在Linux上SQL Server中更改默认数据库文件和备份路径

    sql数据库备份默认路径 In a previous article, we explored the process to change default SQL dump file location ...

最新文章

  1. 让Redis在你的系统中发挥更大作用的几点建议
  2. Science Robotics:仿生手臂的神经机器人感觉运动融合恢复自然行为
  3. 离散数学 第二章 谓词逻辑 2-1 谓词的概念与表示
  4. 直播报名 | 用户中台建设实践解析
  5. Pentium M处理器架构/微架构/流水线 (2) - 数据预取/乱序核/退役单元
  6. API、H5跟风控相关的知识是否了解?
  7. 如何使得OCX控件能响应PreTranslateMessage消息?
  8. 【汇编语言与计算机系统结构笔记04】80x86计算机组织、保护模式、存储器、寄存器、计算机系统结构金字塔
  9. 面试官:CountDownLatch 与 CyclicBarrier 的使用场景?有什么区别?
  10. 高分三号卫星(GF-3)简介
  11. Ubuntu搭建Android NDK开发环境并编译Demo
  12. 在VMware 16.2.2中安装Windows7
  13. VSCode配置Python教程
  14. C++经典算法题-循序搜寻法(使用卫兵)
  15. 完美实现苹果轮廓检测opencv-python检测图像轮廓处理
  16. foxipdf和adobe_过去和将来的活动:Adobe Max North America和CFCAMP澳大利亚
  17. 上证指数开盘指数预测 Matlab
  18. socket读写返回值的处理
  19. VPS服务器能够做些什么?
  20. 【华为2023届校招】集团IT秋招进行中!机会多!专人跟进!欢迎投递!

热门文章

  1. centos7 nat模式配置静态ip_KUKA机器人-配置Ethernet/IP总线为Adaper模式
  2. asp.net 窗体关闭事件_关于滁州一地煤气爆炸事件!最新消息来了!
  3. 配置 MySQL 服务器容器
  4. ubuntu HackRF One相关环境搭建
  5. logstash_output_mongodb插件用途及安装详解
  6. sqlserver 按日、周、月统计方法
  7. andorid之帧布局FrameLayout
  8. 解决Kscope中文乱码问题
  9. DB2 V9 默认帐户信息和服务启动信息
  10. 令人郁闷的DateTime.ToString()方法