首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >sys.indexes型柱

sys.indexes型柱
EN

Database Administration用户
提问于 2023-04-22 17:13:21
回答 2查看 40关注 0票数 0

根据sys.indexestype = 2 -->Nonclustered rowstore (B-tree)的官方文件。但是,下面从online 这里获取的第4行示例显示了type = 2 -->Nonclustered unique。问:类型=2是否意味着非聚集唯一索引。为什么作者在下面第4行中使用unique

代码语言:javascript
复制
select i.[name] as index_name,
    substring(column_names, 1, len(column_names)-1) as [columns],
    case when i.[type] = 1 then 'Clustered index'
        when i.[type] = 2 then 'Nonclustered unique index'
        when i.[type] = 3 then 'XML index'
        when i.[type] = 4 then 'Spatial index'
        when i.[type] = 5 then 'Clustered columnstore index'
        when i.[type] = 6 then 'Nonclustered columnstore index'
        when i.[type] = 7 then 'Nonclustered hash index'
        end as index_type,
    case when i.is_unique = 1 then 'Unique'
        else 'Not unique' end as [unique],
    schema_name(t.schema_id) + '.' + t.[name] as table_view, 
    case when t.[type] = 'U' then 'Table'
        when t.[type] = 'V' then 'View'
        end as [object_type]
from sys.objects t
    inner join sys.indexes i
        on t.object_id = i.object_id
    cross apply (select col.[name] + ', '
                    from sys.index_columns ic
                        inner join sys.columns col
                            on ic.object_id = col.object_id
                            and ic.column_id = col.column_id
                    where ic.object_id = t.object_id
                        and ic.index_id = i.index_id
                            order by key_ordinal
                            for xml path ('') ) D (column_names)
where t.is_ms_shipped <> 1
and index_id > 0
order by i.[name]
EN

回答 2

Database Administration用户

发布于 2023-04-22 17:26:22

类型=2意味着非聚集唯一索引。为什么作者在下面第4行中使用“唯一”?

下面摘录的sys.indexes文档显示类型2是一个非集群的行存储索引。类型本身并不表示索引是唯一的还是非唯一的.单独的is_unique列指定索引是否唯一。

索引类型:0= Heap 1=集群行存储(B)2=非聚集行存储(B)3= XML 4= Spatial 5=聚集列存储索引。适用于: Server 2014 (12.x)及更高版本。6=非聚集列存储索引。应用于: Server 2012 (11.x)及更高版本。7=非聚集散列索引。适用于: Server 2014 (12.x)及更高版本。

我不能说为什么作者在类型2的描述中指定了唯一。我猜这是一个错误。

票数 3
EN

Database Administration用户

发布于 2023-04-23 12:18:39

据我所知,表sys.indexes有一个不同的列,称为is_unique,只有根据它的值,您才能知道它是唯一的索引还是没有唯一的索引。编写查询的人也知道这一点,因为在第11行,他/她还检查is_unique列的值,以便指定此属性。我猜他/她在写“非聚集唯一索引”时在字符串上犯了一个错误。事实上,它们没有新聚集的值,没有唯一的索引,这也意味着这是一个错误。

阿迪

票数 0
EN
页面原文内容由Database Administration提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://dba.stackexchange.com/questions/326298

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档