下面介绍sqlserver 聚集索引和非聚集索引实例:
create database myIndexDemo
go
use myIndexDemo
go
create table ABC
(
A int not null,
B char(10),
C varchar(10)
)
go
insert into ABC
select 1,'B','C'
union
select 5,'B','C'
union
select 7,'B','C'
union
select 9,'B','C'
go
select * from ABC
--在ABC表上创建聚集索引
create clustered index CLU_ABC
on ABC(A)
GO
--查看索引
sp_helpIndex ABC
--插入数据
insert into ABC
values(2,'B','C')
--因为有聚集索引所以整个表的物理结构发生了变化
--此时按照该索引查询的内容为:
select * from ABC WITH(index = CLU_ABC) WHERE A>1 AND A<5