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 A5
--刪除索引后 Drop index ABC.CLU_ABC
--查詢內容物理順序還是按照順序的 select * from ABC
--在ABC表上創建非聚集索引 create nonclustered index NONCLU_ABC on ABC(A)
--查看索引 sp_helpIndex abc
--插入數據 insert into ABC values(4,'B','C')
--因為有聚集索引所以整個表的物理結構發生了變化 --此時查詢的內容為: select * from ABC WITH(index = NONCLU_ABC)