包含sql server索引中的列

时间:2015-02-04 12:17:49

标签: sql-server indexing include

所有非聚集索引(NCI)也将存储聚簇索引(CI)的键列

在创建NCI的过程中,如果我们故意将关键列包含在内,那会再次占用空间吗?

意味着存储键列,会占用两次空间吗?

提前致谢

1 个答案:

答案 0 :(得分:1)

不,空间不会被拍两次。

create table test (id int not null primary key, c1 int, c2 int)

create index ix1_test on test (c1)
create index ix2_test on test (c1) include (id)
create index ix3_test on test (c1) include (id, c2)

sp_SQLskills_SQL2012_helpindex显示以下信息:

index_name  index_description     index_keys    included_columns    columns_in_tree columns_in_leaf
[PK__test]  clustered, unique, PK [id]        NULL                  [id]            All columns "included"
[ix1_test]  nonclustered          [c1]        NULL                  [c1], [id]      [c1], [id]
[ix2_test]  nonclustered          [c1]        [id]                  [c1], [id]      [c1], [id]
[ix3_test]  nonclustered          [c1]        [id], [c2]            [c1], [id]      [c1], [id], [c2]