如何能让下面的程序运行更快

xingyunzt 2004-09-02 02:40:23
有下面几个表
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
但是打开关闭表又太浪费时间,还有什么更好的办法吗?
用视图怎么样? 如果数据量太大会不会有什么问题?
...全文
83 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
xingyunzt 2004-09-04
  • 打赏
  • 举报
回复
我搞定了,先打开所有的表 order by ID,table_a做循环,如果table_b.ID=table_a.ID,做数据处理,循环table_b,如果不等退出循环……这样能保证table_a 做一次movenext的时候,其他的表只做一次movenext,特殊情况可能会多做几次。每个表基本上只做一次遍历就够了。
我的实际的程序有12个表,每个表有800条记录,赛杨900 + 256M + win2k + mssql2k 用原来的算法需要一个多小时,现在用时不超过两分钟
饮水需思源 2004-09-02
  • 打赏
  • 举报
回复
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
lzymagi 2004-09-02
  • 打赏
  • 举报
回复
用视图要比直接用SQL慢.(多了一层SQL)
饮水需思源 2004-09-02
  • 打赏
  • 举报
回复
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
zjcxc 元老 2004-09-02
  • 打赏
  • 举报
回复
逐条怎么都快不起来.
zjcxc 元老 2004-09-02
  • 打赏
  • 举报
回复
直接用sql语句

34,590

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧