T-SQL – Find Database Name and Check if Filestream is Enabled in SQL Server 2014

filestreamsql server 2014t-sql

Please help me on below query .

NOTE : Please excuse my programming skills , the code is of mistakes .

I want the output like Database name in one column and the FileStream enabled or disabled in another column . Just 2 columns I am trying out for . Thanks

To find the Database name and if FileStream is enabled for the Database .

declare @cmd varchar(500)
set @cmd='USE ? 
if exists(
 select name, Filestream from sys.database_files where type_desc='FILESTREAM')
 CASE type_desc WHEN 'FILESTREAM' THEN 'Filestream Configured For Datbase' ELSE 'Filestream NOT Configured For Datbase'
PRINT 'Filestream Configured For Datbase'
else
 print 'Filestream Not configured for database' 
inner join sys.databases where name not in (''master'', ''tempdb'', ''model'', ''msdb'')')
exec sp_MSforeachdb @cmd 

Best Answer

Reference:

I would rephrase you question to find databases that are using FILESTREAM. Because you can only enable FILESTREAM at an instance level in order to use it in any user database.

To find all the files related to FILESTREAM or database name you can use this query.

SELECT db.NAME       AS DBName, 
       type_desc     AS FileType, 
       physical_name AS Location 
FROM   sys.master_files mf 
       INNER JOIN sys.databases db 
               ON db.database_id = mf.database_id 
WHERE  type_desc = 'FILESTREAM'