【发布时间】:2015-02-04 12:17:48
【问题描述】:
所有非聚集索引(NCI)也会存储聚集索引(CI)的键列
在创建 NCI 时,如果我们有意包含键列会发生什么情况,是否会再次占用空间?
意思是存储key column,会不会占用两次空间?
提前致谢
【问题讨论】:
标签: sql-server indexing include
所有非聚集索引(NCI)也会存储聚集索引(CI)的键列
在创建 NCI 时,如果我们有意包含键列会发生什么情况,是否会再次占用空间?
意思是存储key column,会不会占用两次空间?
提前致谢
【问题讨论】:
标签: sql-server indexing include
不,空间不会被占用两次。
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]
【讨论】: