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.

Avatar of undefined
Last Comment

8/22/2022 - Mon
Guy Hengel [angelIII / a3]

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Guy Hengel [angelIII / a3]

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.

Thanks again!!
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck