日期:2014-05-17  浏览次数:20459 次

sql数据库中创建索引的问题?
怎样创建数据库中索引?


聚集索引和非聚集索引的区别?
数据库 索引 sql

------解决方案--------------------
你一下子把问题扩展到无限大了....你最好把你的疑问明确的提出
------解决方案--------------------
--创建聚集索引:
create index idx_col on tb(col)

--创建非聚集索引:
create nonclustered index idx_col on tb(col)


聚集索引的区别

  聚集索引:物理存储按照索引排序

  非聚集索引:物理存储不按照索引排序

优势与缺点

聚集索引:插入数据时速度要慢(时间花费在“物理存储的排序”上,也就是首先要找到位置然后插入),查询数据比非聚集数据的速度快 

聚集索引的区别

  聚集索引:物理存储按照索引排序

  非聚集索引:物理存储不按照索引排序

优势与缺点

聚集索引:插入数据时速度要慢(时间花费在“物理存储的排序”上,也就是首先要找到位置然后插入),查询数据比非聚集数据的速度快 


------解决方案--------------------
引用:
怎样创建数据库中索引?


聚集索引和非聚集索引的区别?


1.如何建索引,
 
if OBJECT_ID('tb') is not null
   drop table tb
go

create table tb(id int,v varchar(10),vv int)

insert into tb
values(1,'abc',10)

insert into tb
values(2,'def',12)

--drop index idx_tb_col on tb

--聚集索引
create clustered index idx_tb_col on tb(id)


--非聚集索引
create nonclustered index idx_tb_col_v on tb(v)

--建立复合索引
create nonclustered index idx_tb_col_v_vv on tb(v,vv)


--建立具有include列的索引
create nonclustered index idx_tb_col_in_v_vv on tb(v) include(vv)


2、聚集索引和非聚集索引的区别。
聚集索引是让数据物理上按照索引字段来排序的索引,也就是说磁盘上的整个表数据,会按照聚集索引列排序,存放。
非聚集索引只是按照索引列排序,比如上面的例子中的idx_tb_col_v索引中只包含了v列。
------解决方案--------------------
我觉得问这种问题的人应该不会create index都不懂的,我觉得他应该是问:怎样建索引才有效
------解决方案--------------------
创建索引的方式
create [索引的类型] index [索引名称] on [表名称]([字段名称],……)

聚集索引你只能建立一个,而非聚集索引你可以建立多个