在SQL Server 2008提供FileStream,以借助Windows系統本身的API來強化SQL Server對於非結構化數據的支持後,SQL Server 2012更是推出了像Contained Database、FileTable等令人期待的新功能。對於FileTable的功能和特性,在此無需贅述,本文主要針對FileTable的T-SQL操作目錄做一個實例演示。
關於FileTable的介紹,請參閱MSDN:http://technet.microsoft.com/zh-cn/library/ff929144.aspx
一、啟用FileTable的先決條件
http://technet.microsoft.com/zh-cn/library/gg509097.aspx
USE master GO EXEC sp_configure 'filestream access level',2 Go RECONFIGURE GO --查看實例級FileTable配置 EXEC sp_configure filestream_access_level; GO
二、創建一個FileTable
USE master
GO
IF EXISTS (SELECT name FROM sys.databases WHERE name = N'LearnFileTable')
DROP DATABASE LearnFileTable
GO
/****** Object: Database [LearnFileTable] Script Date: 2014-04-23 9:25:32 ******/
CREATE DATABASE [LearnFileTable]
CONTAINMENT = NONE
ON PRIMARY
( NAME = N'LearnFileTable_Primary', FILENAME = N'E:\SQL2012Data\MyData\2012Data\LearnFileTable_Data.mdf' ,
SIZE = 8128KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB ),
FILEGROUP [MyFS] CONTAINS FILESTREAM DEFAULT
( NAME = N'LearnFileFS', FILENAME = N'E:\SQL2012Data\MyData\2012Data\LearnFileFS' ,
MAXSIZE = UNLIMITED)
LOG ON
( NAME = N'LearnFileTable_Log', FILENAME = N'E:\SQL2012Data\MyData\2012Data\LearnFileTable_Log.ldf' ,
SIZE = 8128KB , MAXSIZE = 2097152KB , FILEGROWTH = 10%)
WITH FILESTREAM (NON_TRANSACTED_ACCESS = FULL, DIRECTORY_NAME = N'LearnFileTable')
GO
三、創建FileTable數據表
USE LearnFileTable GO CREATE TABLE MyFileTable01 AS FileTable WITH ( FileTable_Directory = 'MyFileTable01', FileTable_Collate_Filename = database_default ); GO select * from [dbo].MyFileTable01;