Mar*_*son 5 t-sql sql-server feature-detection columnstore
我有一个存储过程,可以创建一些动态表.如果主机版本的SQL Server支持列存储索引,那么我想创建一个列存储索引,否则回退到只创建一个普通的行存储索引.
我找到了这个dm_db_persisted_sku_features表,但它只是告诉你当前使用的是什么非标准功能而不是支持的功能:
SELECT * FROM sys.dm_db_persisted_sku_features
Run Code Online (Sandbox Code Playgroud)
如何从查询内部确定SQL Server版本和版本是否支持列存储索引?
您可以检查当前数据库的兼容性级别,看看它是否与2012+功能兼容。
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()
Run Code Online (Sandbox Code Playgroud)
笔记:
SELECT * from sys.system_objects where name='column_store_dictionaries'
Run Code Online (Sandbox Code Playgroud)
存在于不支持列存储索引的版本上(例如 2014 Express)