Home > Database > Mysql Tutorial > sql数据库聚集索引和非聚集索引示例

sql数据库聚集索引和非聚集索引示例

WBOY
Release: 2016-06-07 17:46:54
Original
1529 people have browsed it


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)

--查看索引
sp_helpIndex abc

--插入数据
insert into ABC
values(2,'B','C')

--因为有聚集索引所以整个表的物理结构发生了变化
--此时按照该索引查询的内容为:
select * from ABC (index = NONCLU_ABC)

--删除索引后
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 (index = NONCLU_ABC)

--删除索引后
Drop index ABC.NONCLU_ABC

--查询内容物理顺序是按照插入的顺序
select * from ABC

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template