请教一个问题:我在做查询的时候,速度有时很慢,常出现超时已过期提示,请问:有没有一种很好的提高查询速度的方法。
是不是与我写的SQL语句有关,我的SQL语句是这样的:select top 200 InfoRecordID,CalleeID,CallerID,FeeTerminalID,NeedTime,Content,direction,RetCode,b.user_name username from sendDb..inforecord a left join sys_user b on a.employeeid=b.user_id where (needtime between '2007-1-8' and '2007-1-9') and (calleeid in (select spno from chat_config) or callerid in(select spno from chat_config)) order by needtime desc
请指点。
若建立索引,像我这样的查询语句,应如何建索引较好。
是不是与我写的SQL语句有关,我的SQL语句是这样的:select top 200 InfoRecordID,CalleeID,CallerID,FeeTerminalID,NeedTime,Content,direction,RetCode,b.user_name username from sendDb..inforecord a left join sys_user b on a.employeeid=b.user_id where (needtime between '2007-1-8' and '2007-1-9') and (calleeid in (select spno from chat_config) or callerid in(select spno from chat_config)) order by needtime desc
请指点。
若建立索引,像我这样的查询语句,应如何建索引较好。
解决方案 »
- 当前活动中的“锁/进程 ID”,“锁/对象”,分别是什么意思呀?
- ms server 2005 创建数据库
- 进程死锁
- mysql数据库 乱码情况
- 导出数据时提示:[DBNETLIB][ConectionOpen (connect()).]SQL Server不存在或拒绝访问,这该怎么办呢?
- SQL语句问题
- 很急的问题:存在SQl中的附件无法下载啦!!
- 请教怎样将SQL SERVER里的数据记录生成SQL脚本??!!
- powerdesigner问题
- 请教各位,使用 ADO 时,插入#import "...msado15.dll" 出错(VC6.0)
- 关于查询统计的问题
- sql query analyzer连接记录
另:查询可以这样改.
select top 200 InfoRecordID,CalleeID,CallerID,FeeTerminalID,NeedTime,Content,direction,RetCode into #temp_table
from sendDb..inforecord where (needtime between '2007-1-8' and '2007-1-9') and (calleeid in (select spno from chat_config) or callerid in(select spno from chat_config)) order by needtime desc select top 200 * ,b.user_name username from #temp_table a left join sys_user b on a.employeeid=b.user_id order by needtime desc
这种改法针对sys_user表的记录数效多的情况有效.
我认为应该从数据结构开始修改。
你的SQL中存在跨库查询的部分,会影响速度的。
同时判断条件中最好不要使用or。