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,'C'
union
select 7,'C'
union
select 9,'C'
go select from ABC --在ABC表上创建聚集索引
create clustered index CLU_ABC
on ABC(A)
GO --查看索引
sp_helpIndex ABC --插入数据
insert into ABC
values(2,'C') --因为有聚集索引所以整个表的物理结构发生了变化
--此时按照该索引查询内容为:
select
from ABC WITH(index = CLU_ABC) WHERE A>1 AND A<5 --删除索引后
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,'C') --因为有聚集索引所以整个表的物理结构发生了变化
--此时查询内容为:
select
from ABC WITH(index = NONCLU_ABC) --删除索引后
Drop index ABC.NONCLU_ABC --查询内容物理顺序是按照插入的顺序
select * from ABC

相关文章

SELECT a.*,b.dp_name,c.pa_name,fm_name=(CASE WHEN a.fm_n...
if not exists(select name from syscolumns where name=&am...
select a.*,pano=a.pa_no,b.pa_name,f.dp_name,e.fw_state_n...
要在 SQL Server 2019 中设置定时自动重启,可以使用 Window...
您收到的错误消息表明数据库 &#39;EastRiver&#39; 的...
首先我需要查询出需要使用SQL Server Profiler跟踪的数据库标...