I need to run a variable amount of insert statements. Is it best to run through a loop and execute the query one at a time? Or, is there a way to send all the inserts in one go?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Use a transaction and batch all the inserts. Not sure about the conditions you’re trying to do this under, but if it’s code executing SQL statements, just open the connection, start a transaction, execute everything, and then commit the transaction or roll it back if there was an exception.
Edit Some pseudocode:
Of course you’ll need to enclose this in a try/catch block and rollback the transaction if there’s an exception. But this is basically it.