How to fix The number of row value expressions in the INSERT statement exceeds the maximum allowed number of 1000 row values.

PRANAY KUMAR PANDEY 0 Reputation points
2023-01-27T19:55:06.07+00:00

I am new to SQL and was trying to copy a database for a project.

However, the commands didn't execute accounting to the error

'The number of row value expressions in the INSERT statement exceeds the maximum allowed number of 1000 row values.'

How do I resolve this.

https://docs.google.com/document/d/1-WhNRX1iYJIz7e5l28DMPWgsPklpE_w6/edit

The above link is the source file what I am creating a database from.

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
13,791 questions
{count} votes

5 answers

Sort by: Most helpful
  1. Jingyang Li 5,891 Reputation points
    2023-01-27T21:01:22.12+00:00

    One option is that you can split your insert statement from one big INSERT into statement to multiple INSER into with items <=1000 rows for each INSERT in your script.

    0 comments No comments

  2. Erland Sommarskog 111.1K Reputation points MVP
    2023-01-27T22:33:22.8266667+00:00

    As the error messages says, in SQL Server you cannot have more than 1000 rows in an INSERT VALUES clause. This may seem like a corny restriction, but it is there to protect you from sever performance issues. If you instead use SELECT UNION ALL SELECT etc, there is no limitation, you can insert 50000 rows that way, but the performance is horrible. Not to execute the statement, but to parse and compile it.

    Anyway, in your case, I guess you need to use the scripting language of your choice to break up the statements so they have fewer rows. The simplest is probably to only have one VALUES per INSERT, but that will be slow for other reasons. Then again, you can improve speed quite a bit in that case by wrapping the operation in BEGIN TRANSACTION and COMMIT TRANSACTION.

    0 comments No comments

  3. Vladimir Moldovanenko 256 Reputation points
    2023-01-28T13:40:25.53+00:00

    You can also use

    Insert into table

    select * from

    (values (…….) v( coll,…)

    it does not have that limitation.

    0 comments No comments

  4. LiHongMSFT-4306 27,016 Reputation points
    2023-01-30T06:02:07.5133333+00:00

    Hi @PRANAY KUMAR PANDEY

    'The number of row value expressions in the INSERT statement exceeds the maximum allowed number of 1000 row values.'

    When used as a derived table, there is no limit to the number of rows.

    When used as the VALUES clause of an INSERT ... VALUES statement, there is a limit of 1000 rows. Error 10738 is returned if the number of rows exceeds the maximum. To insert more than 1000 rows, use one of the following methods:

    Please refer to this doc for more details: Table Value Constructor (Transact-SQL)

    Best regards,

    Cosmog Hong


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our Documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

  5. Modrall, Mark 0 Reputation points
    2024-07-26T15:16:41.8166667+00:00

    Just ran into this and tried a work-around.

    Turns out using the

    INSERT INTO Foo SELECT bar FROM (Values (1), (2), (3)) x(bar)

    syntax is not subjected to that 1000 limit

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.