Link to home
Start Free TrialLog in
Avatar of infodigger
infodigger

asked on

Inserting several records at once. Which is the best way?

In a script I have written, I execute about 1000 inserts to the database. Currently I am using a for each statement and execute each insert one by one. It takes some time so I was wondering if there is a faster way to do this. For example I could be a query that runs all the queries together and run it in the end of the for each statement but I don't know if it would be faster.
ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
note: the above suggestion should be magnitues faster that inserting each row individually as bascially only 1 database call/transaction is involved instead of hundreds/thousands
note: if there are many more, you will need to "split" into inserts of something like 1000-2000 rows at once maximum, otherwise you might reach some other limits.
Avatar of infodigger
infodigger

ASKER

Thanks again!!