关于网友提出的“ 大家帮忙看一下,这个执行效率太低了”问题疑问,本网通过在网上对“ 大家帮忙看一下,这个执行效率太低了”有关的相关答案进行了整理,供用户进行参考,详细问题解答如下:
问题: 大家帮忙看一下,这个执行效率太低了
描述: 程序代码如下:只是执行的效率太低,能不能帮我改一下? 如果数据库有几千条记录就相当慢了.
...
for i:=low(persons) to high(persons) do
begin
for j:=low(areaname) to high(areaname) do
begin
op.SQL.Clear;
op.SQL.Add('select * from [em] where area='''+areaname[j].Name+''' and ID='''+persons[i].id+'''');
op.Open;
while not op.Eof do
begin
IsExist:=true;
op.Next;
end;
if IsExist=false then
begin
pop.SQL.Clear;
pop.SQL.Add('insert into [em] '+
'(name,age,id,sex) '+
'values ('''+persons[i].Name+''',10,0001,1)');
pop.ExecSQL;
pop.Close;
end;
op.Close;
IsExist:=false;
end;
end;
解决方案1: 1) 'select count(*) from [em] where area='''+areaname[j].Name+''' and ID='''+persons[i].id+''''
看看值为多少就可以了------减少网络数据流量
2) 尝试一下索引的影响
3) 不过觉得这里的有没有重复纪录的判断不需要,可以在别的地方作保证。??----请大家发表意见
4) 关于add一个Record如果很频繁,建议使用存储过程(使用事务处理)
解决方案2: 改称
op.open;
if op.recordcount > 0 then isexist = true;可以吗?
以上介绍了“ 大家帮忙看一下,这个执行效率太低了”的问题解答,希望对有需要的网友有所帮助。
本文网址链接:http://www.codes51.com/itwd/3459954.html