Introduction to SQL Server 2012 FileTables

This article will introduce the relevant SQL Server 2012 FileTables.


We all know that this kind of like the SQL Server relational database adept at handling large amount of structured data, files or directories for this type of unstructured data management and query is relatively difficult to handle.

General web application development, for example, often need to provide users through the browser function to upload files, applications, how to record information about these files, generally are based on these two methods, one is only in the DBMS record in the file name, size, type and other information, the actual file is stored in which file systems, and second, to save the DBMS after the upload file into a binary.

Both methods have their advantages and disadvantages, the former problem is that when you back up a database, stored in the file system file or directory, need to find their own way to do a backup, in other words, the database and instance files are independent. Examples of the latter will be transferred into a binary data, the problem easily derived on the performance or save space.

Now this problem in SQL Server 2012 to add special data table (FileTables) already solved most of the problems, which is based FILESTREAM technology, and provides full-text search and (Full-Text Searc) and semantic search (Semantic Search), etc. Advanced search integration. Through FileTables You can only use T-SQL can read the file, directory and file attributes such as class information, and can be integrated backup feature, as long as the backup database, will together with FileTables file or directory backup with the future, not It will give rise to performance, or database save space. Next, we will introduce how to set up and use FileTables.

Enable FileTables There are several necessary conditions, as follows:

  1. Instance level must be enabled FILESTREAM.
  2. You must establish a dedicated file group for FILESTREAM.
  3. Only use non-transactional access (Non-transactional access) in the database level.
  4. Establish FileTables data sheet.

Special mention is to assume that your SQL Server is installed on a 64-bit operating system, and your SQL Server is to install the 32-bit version, you can not enable FILESTRAM function, this point is in the planning before installation SQL Server must consider clear.

Next author illustrates how the above-described four steps should be performed:


  1. Instance level must be enabled FILESTREAM.
    You can start at [> execution>] enter SQLServerManager11.ms open SQL Server Configuration Manager. Check the Enable FILESTRAM for Transact-SQL access, and set the share name of the directory, and then restart the Database Engine service.

    2012-06-02_154516

    After the service restarts, and then set the following T-SQL FILESTREAM ACCESS LEVEL:

       1:  EXEC sp_configure filestream_access_level, 2 
       2:  GO
       3:  RECONFIGURE
       4:  GO


  2. You must establish a dedicated file group for FILESTREAM.
    Because FileTables this particular data table, you can not be saved in a file group in general, so this step must be the establishment of a dedicated FILESTREAM file group with the following T-SQL when you create a database (as described in Section 12 of the program) :

       1:  DECLARE @DB_Name NVARCHAR(64) = N'FTDB'
       2:  DECLARE @device_directory NVARCHAR(256)
       3:  SELECT @device_directory = SUBSTRING(filename, 1, CHARINDEX(N'master.mdf', LOWER(filename)) - 1)
       4:  FROM master.dbo.sysaltfiles WHERE dbid = 1 AND fileid = 1
       5:   
       6:  IF DB_ID(@DB_Name) > 0
       7:  EXEC ('DROP DATABASE ' + @DB_Name)
       8:   
       9:  EXEC (
      10:  N'CREATE DATABASE ' + @DB_Name
      11:    + ' ON PRIMARY (NAME = N''FTData'', FILENAME = N''' + @device_directory + N'FTData.mdf'') '
      12:    + ', FILEGROUP FSFileGroup CONTAINS FILESTREAM( NAME = FTData1, FILENAME = N''' + @device_directory +N'FTData1'') '
      13:    + 'LOG ON (NAME = N''FTLog'',  FILENAME = N''' + @device_directory + N'FTLog.ldf'')'
      14:  )
      15:  GO



  3. Once created, you can see a similar result in the following figure just created database properties:

  4. Only use non-transactional access (Non-transactional access) in the database level.


    2012-06-01_062422
  5. Establish FileTables data sheet.
    You can use two ways to create FileTable:

       1: - a method, specify the directory name and sequencing

       2:  CREATE TABLE MyFileTable AS FileTable

       3:      WITH ( 

       4: FileTable_Directory = 'FileTables', - specify the directory name

       5: FileTable_Collate_Filename = sequencer database_default-- name specified data row

       6:           )

       7:  GO

       8:   

       9: - The second method uses the default directory name

      10:  CREATE TABLE MyFileTable2 AS FileTable

      11:  GO

If successfully establish successful, you will be [Object Explorer> database name> Tables> FileTables] see next item FileTable you create, and you can see that SQL Server can help you manage those unstructured information file (as shown below ).


2012-06-03_141604

This article first introduced to this, the next article, I will show you how to file into the SQL Server 2012 management of FileTables.

[Reference Data]

  • FileTables (SQL Server)

Original: Big Box  SQL Server 2012 FileTables Profile


Guess you like

Origin www.cnblogs.com/chinatrump/p/11516469.html