The FileTable feature brings support for the Windows file namespace and compatibility with Windows applications to the file data stored in SQL Server. FileTable lets an application integrate its storage and data management components, and provides integrated SQL Server services - including full-text search and semantic search - over unstructured data and metadata.(FileTable)
Here is sequential SQL statements to enable,alter existing database for FileStream and create FileTable
--check current config value
EXEC sp_configure filestream_access_level;
--reconfig
GO
EXEC sp_configure 'filestream access level', 2
Go
RECONFIGURE
GO
-- chack file table enabled databases
SELECT DB_NAME(database_id) as [Database Name],
non_transacted_access,
non_transacted_access_desc
,directory_name
FROM sys.database_filestream_options
-- Enable a file table in an existing Database
ALTER DATABASE TestDB
SET FILESTREAM ( NON_TRANSACTED_ACCESS = FULL, DIRECTORY_NAME = N'testFileTable' )
GO
--create file table
CREATE TABLE MyFirstFileTable AS FileTable
WITH
(
FileTable_Directory = 'MyFirstFileTable',
FileTable_Collate_Filename = database_default
);
GO
-- DB Operations on FileTable
USE [TestDB]
GO
SELECT [stream_id]
,[file_stream]
,[name]
,[path_locator]
,[parent_path_locator]
,[file_type]
,[cached_file_size]
,[creation_time]
,[last_write_time]
,[last_access_time]
,[is_directory]
,[is_offline]
,[is_hidden]
,[is_readonly]
,[is_archive]
,[is_system]
,[is_temporary]
FROM [dbo].[MyFirstFileTable]
GO
select FileTableRootPath() as rootPath
--update [dbo].[MyFirstFileTable] set [name]='Aquabella.xlsx' where [name]='Aquabella 91.xlsx'
--get root level UNC path
select FileTableRootPath() --1
select FileTableRootPath('[dbo].[MyFirstFileTable]',0) --2
select FileTableRootPath('[dbo].[MyFirstFileTable]',1) --3
--full files path
SELECT FileTableRootPath() + file_stream.GetFileNamespacePath() As FullPath,[name] as [FileName]
FROM [dbo].[MyFirstFileTable]
Here is sequential SQL statements to enable,alter existing database for FileStream and create FileTable
--check current config value
EXEC sp_configure filestream_access_level;
--reconfig
GO
EXEC sp_configure 'filestream access level', 2
Go
RECONFIGURE
GO
-- chack file table enabled databases
SELECT DB_NAME(database_id) as [Database Name],
non_transacted_access,
non_transacted_access_desc
,directory_name
FROM sys.database_filestream_options
-- Enable a file table in an existing Database
ALTER DATABASE TestDB
SET FILESTREAM ( NON_TRANSACTED_ACCESS = FULL, DIRECTORY_NAME = N'testFileTable' )
GO
--create file table
CREATE TABLE MyFirstFileTable AS FileTable
WITH
(
FileTable_Directory = 'MyFirstFileTable',
FileTable_Collate_Filename = database_default
);
GO
-- DB Operations on FileTable
USE [TestDB]
GO
SELECT [stream_id]
,[file_stream]
,[name]
,[path_locator]
,[parent_path_locator]
,[file_type]
,[cached_file_size]
,[creation_time]
,[last_write_time]
,[last_access_time]
,[is_directory]
,[is_offline]
,[is_hidden]
,[is_readonly]
,[is_archive]
,[is_system]
,[is_temporary]
FROM [dbo].[MyFirstFileTable]
GO
select FileTableRootPath() as rootPath
--update [dbo].[MyFirstFileTable] set [name]='Aquabella.xlsx' where [name]='Aquabella 91.xlsx'
--get root level UNC path
select FileTableRootPath() --1
select FileTableRootPath('[dbo].[MyFirstFileTable]',0) --2
select FileTableRootPath('[dbo].[MyFirstFileTable]',1) --3
--full files path
SELECT FileTableRootPath() + file_stream.GetFileNamespacePath() As FullPath,[name] as [FileName]
FROM [dbo].[MyFirstFileTable]
Hope it helps,Thanks
Comments
Post a Comment