创建索引后,查询的结果还是和原来一样,为什么?

史瑞克IV 2015-08-25 07:48:06
create index index1 on _Employee(e_salary desc);

select * from _Employee;

...全文
179 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
Tiger_Zhao 2015-08-26
  • 打赏
  • 举报
回复
非聚集索引不影响结果。
要排序直接用 ORDER BY。
Mr_Nice 2015-08-26
  • 打赏
  • 举报
回复
--> 测试数据: [TY]
if object_id('[TY]') is not null drop table [TY]
create table [TY] (e_id int,e_store int,e_name varchar(4),e_sex varchar(2),e_salary int)
insert into [TY]
select 7,6,'于鹏','男',4000 union all
select 2,3,'李四','男',7000 union all
select 5,6,'王丫','女',4500 union all
select 9,1,'吴敏','女',4800

select * from [TY]



CREATE CLUSTERED INDEX e_salary ON TY(e_salary)
go

/*
e_id	e_store	e_name	e_sex	e_salary
7	6	于鹏	男	4000
5	6	王丫	女	4500
9	1	吴敏	女	4800
2	3	李四	男	7000*/
卖水果的net 版主 2015-08-26
  • 打赏
  • 举报
回复
LZ 的意思,是不是没有按你的索引排序? 这个你有两个方法 1.建立 clustered create clustered index index1 on _Employee(e_salary desc); 2.使用order by 子句。 select * from _Employee order by e_salary desc 另外:索引是否使用,建议你学学基础知识。
woshinidayeQYS 2015-08-25
  • 打赏
  • 举报
回复
使用查询计划,看看计划中用到索引没,一般数据少建索引反而是累赘
专注or全面 2015-08-25
  • 打赏
  • 举报
回复
建了索引,查询时候没用上 这样试试select * from _Employee with (index(index1 ))

34,838

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧