我使用unidac组件。我对快速插入大约 1000 行有问题。
var
query: TUniquery;
begin
query.SQL.Add('INSERT INTO Table (field1,field2,field3) VALUES (:b0,:b1,:b2);');
for I := 0 to 1000 do
begin
Query.ParamByName('b0').AsInteger := 1;
Query.ParamByName('b1').AsInteger := 2;
Query.ParamByName('b2').AsInteger := Random(100);
Query.Prepare;
Query.Execute; //1000 times is very slow
end;
它更快
var
query: TUniquery;
begin
for I := 0 to 1000 do
Query.SQL.Add('INSERT INTO Table (field1,field2,field3) VALUES (1,2,Random(100));');
end;
Query.Execute; //1 times - is fast add
end;
但是,我想将第一种格式与过程 Query.ParamByName('b1').AsInteger := 2; 因为它更清晰并且有大量的列,我发现自己更容易找到。
您对如何解决这个问题有任何想法吗?
也许您还有其他方法可以快速插入具有不同数据的大量行?