Skip to main content

SQL Server(from 2012) FileTable Features some useful SQL Statements

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]  

Hope it helps,Thanks

Comments

Popular posts from this blog

Cannot access a disposed object. A common cause of this error is disposing a context that was

  Cannot access a disposed object. A common cause of this error is disposing a context that was resolved from dependency injection and then later trying to use the same context instance elsewhere in your application. This may occur if you are calling Dispose() on the context, or wrapping the context in a using statement. If you are using dependency injection, you should let the dependency injection container take care of disposing context instances. Object name: 'PropertyContext'.  public class CustomerHub : Hub     {         public readonly ICustomerService _customerService;         private readonly IServiceScopeFactory _serviceScopeFactory;         public CustomerHub(ICustomerService service, IServiceScopeFactory serviceScopeFactory)         {             _customerService = service;             _serviceScopeFactory = serviceSco...

First J2ME Application & Deployment(.jar,.jad) for your Supported Mobile Phones

Most probably 2 years ago I had decided to swap from C#.NET to Java.But at the time of its beginning I found it so messy than that of C#.As I desired to develop applications for my famous China Phone(Network down most of the time but supports java) at last I did it at the end of 2010.Now I'll discuss how to prepare your desktop to develop your first  j2me applications .   What is actually J2ME? J2ME stands for Java 2 Micro Edition, also known as Java ME. J2ME is a stripped down version of Java targeting devices with lower processing capabilities, like mobile phones, pagers .J2ME runs on a highly optimized version of Java Run-time Environment called KVM which comes pre-installed on devices(mobile phone,hand-held devices) supporting J2ME apps. Basic Concepts on J2ME: We can divide J2ME framework into three main parts namely Configurations, profiles and optional packages Configurations : A configuration contains the KVM and important class libraries, It defin...