TSQL query to find Enterprise features availability in a SQL Server Instance

-> Below query can be used to find if a database instance uses Enterprise features or not.

set nocount on
Declare @name varchar(255)
declare @sql varchar(max)
create table #Features(
ServerName varchar(29),
DatabaseName varchar(100),
feature_name varchar(100),
feature_id int)
DECLARE db_cursor CURSOR FOR
SELECT name FROM sys.databases
OPEN db_cursor

DECLARE DatabaseBackup_cursor CURSOR FOR
select name from sys.databases where state=0
OPEN DatabaseBackup_cursor
FETCH NEXT FROM DatabaseBackup_cursor into @name
WHILE @@FETCH_STATUS = 0
BEGIN

set @sql = 'SELECT @@servername,''['+@name+']'' as DatabaseName,*
FROM ['+@name+'].sys.dm_db_persisted_sku_features
ORDER BY feature_name;'

insert into #Features
exec (@sql)
FETCH NEXT FROM DatabaseBackup_cursor into @name
END
CLOSE DatabaseBackup_cursor
DEALLOCATE DatabaseBackup_cursor
CLOSE db_cursor
DEALLOCATE db_cursor
select * from #Features
drop table #Features

-> I use this query predominantly to see if existing Enterprise edition SQL Server instances use Enterprise features or not. This allows me to see if a SQL Server instance can be moved to Standard edition from Enterprise if there are no enterprise features used.

Thank You,
Vivek Janakiraman

Disclaimer:
The views expressed on this blog are mine alone and do not reflect the views of my company or anyone else. All postings on this blog are provided “AS IS” with no warranties, and confers no rights.

Leave a Reply