首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

为什么这个语句会使用索引解决思路

2012-01-13 
为什么这个语句会使用索引创建了一个表t2,设置其中的id列为簇索引,向其中插入2000条数据createtablet2(idi

为什么这个语句会使用索引
创建了一个表t2,设置其中的id列为簇索引,向其中插入2000条数据
create   table   t2
(
      id   int   primary   key,
      id2   int   identity(1,1)
)
go  
declare   @n   int
set   @n=0
while   @n <2000
begin
insert   into   t2(id)   values(@n)
set   @n=@n+1
end


然后使用如下sql:select   id2   from   t2
我察看执行计划时发现使用了id列上的索引,这是为什么阿?
我没有在id2列上建立索引阿



[解决办法]
primary key 和 unique 约束会自动建立唯一性索引。
[解决办法]
sql server 的 unique 是靠索引来实现的.......
pk当然也是

select id2 from t2
默认会使用 pk的排序 规则

热点排行