Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7844119
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T16:46:38+00:00 2026-06-02T16:46:38+00:00

Possible Duplicate: Multiple INSERT statements vs. single INSERT with multiple VALUES Im doing some

  • 0

Possible Duplicate:
Multiple INSERT statements vs. single INSERT with multiple VALUES

Im doing some performance analysis on transactions for batch processing for a blog post and I’ve noticed that when you use a batch insert statement it performs much slower than the equivalent individual SQL statements.

inserting 1000 rows as below takes approx 3s

INSERT TestEntities (TestDate, TestInt, TestString) VALUES  
('2011-1-1', 11, 'dsxcvzdfdfdfsa'),
('2011-1-1', 11, 'dsxcvzdfdfdfsa'),
('2011-1-1', 11, 'dsxcvzdfdfdfsa')

inserting 1000 rows as below takes 130ms

INSERT TestEntities (TestDate, TestInt, TestString) VALUES ('2011-1-1', 11, 'dsxcvzdfdfdfsa')
INSERT TestEntities (TestDate, TestInt, TestString) VALUES ('2011-1-1', 11, 'dsxcvzdfdfdfsa')
INSERT TestEntities (TestDate, TestInt, TestString) VALUES ('2011-1-1', 11, 'dsxcvzdfdfdfsa')

This only appears to happen on the first time you use a batch insert on the table but its reproducible.

Also note the data im inserting is random (but the same for both queries)

EDIT:

heres my repro case with the dummy random data im using for this case: https://gist.github.com/2489133

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T16:46:39+00:00Added an answer on June 2, 2026 at 4:46 pm

    The issue here according to Multiple INSERT statements vs. single INSERT with multiple VALUES is that when SQL gets the query it has to calculate a query plan on first execution. For a single insert this is nice and quick, as there’s not much to calculate, and after it has built the query plan it just re-uses it 1000 times.

    in the batch scenario there are 3k variables which need to be built into the query plan which takes much longer to calculate.

    One crazy feature which @MartinSmith points out is that there is a magic performance number around a batch size of up to 250 rows which means that the plan calculation is very low.

    breaking my above query into 5 200 row statements reduces the execution time to 94ms for 1000 rows

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: How do I replace multiple spaces with a single space in C#?
Possible Duplicate: insert multiple rows via a php array into mysql I know about
Possible Duplicate: Combine multiple results in a subquery into a single comma-separated value Concat
Possible Duplicate: Substitute multiple whitespace with single whitespace in Python trying to figure out
Possible Duplicate: Declaring Multiple Variables in JavaScript I was setting some variables in jQuery
Possible Duplicate: returning multiple values from a function Suppose i have passed two values
Possible Duplicate: jQuery attribute selector for multiple values I have this $('input:radio[name=foo]').change(function() { blah();
Possible Duplicate: Combine multiple Collections into a single logical Collection? I have a lot
Possible Duplicate: Returning multiple values from a C++ function /************************************************/ /* Name: premserv */
Possible Duplicate: Replace multiple whitespaces with single whitespace in JavaScript string I have used

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.