你的意思是添加个事务,速度可以加快吗 -------------------------------- 是 var I: Integer; begin //方法1 使用事务 con1.BeginTrans; try for I := 0 to 100 do begin qry1.SQL.Text := 'insert into Ta ...'; qry1.ExecSQL; end; con1.CommitTrans; except on E: Exception do begin con1.RollbackTrans; raise Exception.Create(e.Message); end; end; //方法2 MSSQL支持';'分隔, 可以拼接后提交, 如果数据量大, 可以考虑分段执行 try qry1.SQL.Text := ''; for I := 0 to 100 do begin qry1.SQL.Text := qry1.SQL.Text + 'insert into Ta ...;'; end; qry1.ExecSQL; except on E: Exception do raise Exception.Create(e.Message); end; end;
------------------------------------------------------------
数据连接控件支持事务, 提交速度很快.如果是使用MSSQL脚本导DBF, 在导入前关闭数据库日志, 可以提高速度.
我用delphi的控件去读取DBF,然后再插入到SQL server里,但速度很慢。
你的意思是添加个事务,速度可以加快吗
你的意思是添加个事务,速度可以加快吗
--------------------------------
是
var
I: Integer;
begin
//方法1 使用事务
con1.BeginTrans;
try
for I := 0 to 100 do
begin
qry1.SQL.Text := 'insert into Ta ...';
qry1.ExecSQL;
end; con1.CommitTrans;
except
on E: Exception do
begin
con1.RollbackTrans;
raise Exception.Create(e.Message);
end;
end;
//方法2 MSSQL支持';'分隔, 可以拼接后提交, 如果数据量大, 可以考虑分段执行
try
qry1.SQL.Text := '';
for I := 0 to 100 do
begin
qry1.SQL.Text := qry1.SQL.Text + 'insert into Ta ...;'; end;
qry1.ExecSQL; except on E: Exception do
raise Exception.Create(e.Message);
end;
end;