如何提高查询上千万数据库表的速度?
如何提高查询上千万数据库表的速度?
用下面的查询语句 用了5分11秒 共 23671149条
select count(*) as a from tworkhis 速度太慢了
而且我要用的查询语句是下面的存储过程
麻烦各位高手帮忙解决下!!
ALTER proc [dbo].[prc_seqcode]
(
@workline varchar(10),--组别
@startTime varchar(8),--日期 如:2011-3-1
@endTime varchar(8), --时间段 如:00:00:00
@selDate varchar(10),--结束时间段 如:23:00:00
@check char(1)--区分不同的查询语句
)
as
begin
if @check=0
begin
select seqcode ,count(*) count_output
from tworkhis where workline =@workline
and frtime between convert(varchar(10),getdate(),120) +' '+@startTime
and convert(varchar(10),getdate(),120) +' '+@endTime group by seqcode
end
if @check=1
begin
select seqcode ,count(*) count_output
from tworkhis where workline =@workline
and frtime between @selDate +' '+@startTime
and @selDate +' '+@endTime group by seqcode
end
end