我的数库据里有20多个表,其中表中数据最多的一个表达到160万条,我在数据表上建立了索引,使用存储过程进行处理,但为什么速度处理还是很慢,主要是表与表的数据传输,请问有没有速度快一点的方法:
比如下一个存储过程:
CREATE PROCEDURE dayPrintproc @date1 datetime,@date2 dateTime AS
if exists (select * from sysobjects where id = OBJECT_ID('[dayPrint]') and OBJECTPROPERTY(id, 'IsUserTable') = 1) DROP TABLE [DayPrint] 
CREATE TABLE dayPrint(ms01 varchar(10),ms02 varchar(20),ms03 float,ms04 float,ms05 float,ms06 float,ms07 float,ms08 float)
insert into dayPrint(ms01,ms02) select ms07,ms02 from dt04
update dayprint set ms03=0
update dayprint set ms04=0
update dayprint set ms05=0
update dayprint set ms06=0
update dayprint set ms07=0
update dayprint set ms08=0
update dayPrint set ms07=(select Sum(ms15) from et22 where (ms03=dayPrint.ms02) and ms20>@date1 and ms20<@date2) where (select Sum(ms15) from et22 where (ms03=dayPrint.ms02))<>0
update dayPrint set ms08=(select Sum(ms18) from et22 where (ms03=dayPrint.ms02) and ms20>@date1 and ms20<@date2) where (select Sum(ms18) from et22 where (ms03=dayPrint.ms02))<>0
update dayPrint set ms05=(select Sum(ms08) from et25 where (ms02=dayPrint.ms02) and ms20>@date1 and ms20<@date2) where (select Sum(ms08) from et25 where (ms02=dayPrint.ms02))<>0
update dayPrint set ms06=(select Sum(ms10) from et25 where (ms02=dayPrint.ms02) and ms20>@date1 and ms20<@date2) where (select Sum(ms10) from et25 where (ms02=dayPrint.ms02))<>0
update dayprint set ms03=ms07-ms05+0
update dayprint set ms04=ms08-ms06+0
其中et22表中有25万条数据,而et25中有70万条数据。

解决方案 »

  1.   

    简单提点意见
    update dayprint set ms03=0
    update dayprint set ms04=0
    update dayprint set ms05=0
    update dayprint set ms06=0
    update dayprint set ms07=0
    update dayprint set ms08=0
    这几句可以不要,在建表的过程中可以使用default来解决,直接设为零,另外,也可以将这几句合并为一句来写update dayprint set ms03=ms07-ms05+0
    update dayprint set ms04=ms08-ms06+0
    这两句也可以合并为一句