如何能让下面的程序运行更快
有下面几个表
table_a table_b table_c
ID name ID age ID sex
要将这些信息合在一起
table
ID name age sex
如果不用视图
在VB中用什么算法比较快
原程序的算法是 先打开三个表
do until 对table_a 做循环
do until 对table_b 做循环
if table_a.id = table_b.id
table.age = table_b.age
end
do until 对table_c 做循环
if table_a.id = table_c.id
table.sex = table_b.sex
end
感觉比较浪费时间,我给改成了
do until 对table_a 做循环
select age from table_b where table_a.id = table_b.id
table.age=table_b.age
select sex from table_c where table_a.id = table_c.id
table.sex=table_c.sex
但是打开关闭表又太浪费时间,还有什么更好的办法吗?
用视图怎么样? 如果数据量太大会不会有什么问题?
问题点数:20、回复次数:6Top
1 楼zjcxc(邹建)回复于 2004-09-02 14:43:35 得分 10
直接用sql语句Top
2 楼zjcxc(邹建)回复于 2004-09-02 14:43:52 得分 0
逐条怎么都快不起来.Top
3 楼lzymagi(逸)回复于 2004-09-02 14:45:33 得分 5
用视图要比直接用SQL慢.(多了一层SQL)Top
4 楼Leftie(左手,为人民币服务)回复于 2004-09-02 14:45:33 得分 5
select a.id ,name,age,sex from table_a as a,table_b as b,table_c as c
where a.id=b.id and a.id=c.id and b.id=c.id
Top
5 楼Leftie(左手,为人民币服务)回复于 2004-09-02 14:46:07 得分 0
select a.id ,name,age,sex from table_a as a,table_b as b,table_c as c
where a.id=b.id and a.id=c.id and b.id=c.id
Top
6 楼xingyunzt(星云)回复于 2004-09-04 08:50:52 得分 0
我搞定了,先打开所有的表 order by ID,table_a做循环,如果table_b.ID=table_a.ID,做数据处理,循环table_b,如果不等退出循环……这样能保证table_a 做一次movenext的时候,其他的表只做一次movenext,特殊情况可能会多做几次。每个表基本上只做一次遍历就够了。
我的实际的程序有12个表,每个表有800条记录,赛杨900 + 256M + win2k + mssql2k 用原来的算法需要一个多小时,现在用时不超过两分钟Top




