sql server 2012 数据量大怎么查询统计

sql server 2012 数据量大怎么查询统计,第1张

你需要做月结存。也就是说 *** 作的表一直只是当月的,以前月份的再另外一张表。

表结构中使用日期做为聚集索引。

如果查询时间只是当月,那么就只从当月出数据

如果查询是以前月份的就从以前月份出数据,如果是查询有当前月也有以前月那么才分别从两表出数据。

另外查询记录如果超过1万条最好top 10000

超过1万条查询结果对用户来说是没用的。

你的数据库是什么数据库?如果是ACCESS,建议你导入到MySQL中去,MySQL据说是世界上执行速度最快的数据库了,如果是MSSQL,请使用存储过程执行查询,可以大提高数据库的运行速度。你的问题我曾经碰到过,当时我使用的是ACCESS数据库,数据库中的数据达到20万条记录了,查询起来速度特慢,后来改用MSSQL的存储过程,速度提高了很多,你试试吧,祝你成功!

create table t5 ( item varchar(20))

insert t5 select '1-10000'

union all select '10000-20000'

union all select '20000-30000'

union all select '40000-50000'

create table t6 (id int identity(1,1),item varchar(20))

insert into t6

select from t5

create table #t6 (id int,item varchar(20))

declare @i int

declare @c int

select @i= min(id) from t6

select @c=max(id) from t6

while (@i<@c)

begin

insert into #t6

select t1id, t1item from t6 t1,t6 t2 where substring(t2item, 1, Charindex('-',t2item)-1)=substring(t1item, Charindex('-',t1item)+1,len(t1item)) and t2id=@i

insert into #t6

select t1id, t1item from t6 t1,t6 t2 where substring(t1item, 1, Charindex('-',t1item)-1)=substring(t2item, Charindex('-',t2item)+1,len(t2item)) and t1id=@i

set @i=@i+1

end

select distinct from #t6

select max(aa) from A where bb = 123456

这样的语法已经是最快的了,至于速度慢就要从程序或者数据库方面找问题了。

先从查询分析器中看看耗时多少,然后在程序中看看耗时多少,来确定是哪里的问题。

这么简单的查询2亿的数据库也不会超过1秒才对。

-------------------

一楼和二楼的回答显然多少有点随便。

为需要作为查询条件的字段建立索引,比如说表中有个字段是“记录时间”,为其建立索引后,在按“记录时间”查询的时候就会比较快。

----------------------------------

网页?你没用到分页技术吗?

以上就是关于sql server 2012 数据量大怎么查询统计全部的内容,包括:sql server 2012 数据量大怎么查询统计、数据库表中大量的数据,如何提高查询速度、sql数据有几百万条记录,如何应用查询语句查询出1-10000、10000-20000、以此类推。等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/sjk/9613990.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-30
下一篇 2023-04-30

发表评论

登录后才能评论

评论列表(0条)

保存