Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Query to identify if current SQL Server version supports columnstore indexes

I have a stored procedure that creates some dynamic tables. If columnstore indexes are supported on the host version of SQL Server then I want to create a columnstore index, otherwise fallback to creating just a normal row store index.

I have found the dm_db_persisted_sku_features table but that just tells you what non-standard features are currently being used rather than what is supported:

SELECT * FROM sys.dm_db_persisted_sku_features

How can I determine from inside a query if the SQL Server version and edition support columnstore indexes?

like image 795
Mark Robinson Avatar asked Nov 09 '22 02:11

Mark Robinson


1 Answers

You can check the compatibility level of the current database to see if it is compatible with 2012+ features.

select 
  ColumnStore = case 
    when compatibility_level >= 110 
        and (serverproperty ('edition') like 'Enterprise%'
          or serverproperty ('edition') like 'Developer%')
      then 1 
    when compatibility_level >= 130 
      and serverproperty ('productlevel') != 'RTM'
      then 1 
    else 0 
    end
  from sys.databases 
  where name = db_name()

note:

SELECT * from sys.system_objects where name='column_store_dictionaries'

exists on editions that do not support columnstore indexes (e.g. 2014 Express)

like image 167
SqlZim Avatar answered Nov 15 '22 08:11

SqlZim