How many rows can SQL Server process in a single INSERT statement into a table?











up vote
4
down vote

favorite
1












To illustrate my question, the following is a query detecting order's id which have not been inserted in a data warehouse and inserts them:



With NewOrders 
As
(
Select OrderID From Orders
Except
Select OrderID From FactOrders
)
Insert Into FactOrders(OrderID, OrderDate, CustomerId)
Select OrderID, OrderDate, CustomerId From Orders
Where OrderID in (Select OrderID from NewOrders);


Say the query is run for the first time and Orders contains 400 million rows or more:



Can SQL Server handle this number of rows in one single INSERT statement?



If not, how should I proceed? Should I limit the number of rows fetched in the INSERT statement? How many rows can the engine handle in a single INSERT statement?










share|improve this question




























    up vote
    4
    down vote

    favorite
    1












    To illustrate my question, the following is a query detecting order's id which have not been inserted in a data warehouse and inserts them:



    With NewOrders 
    As
    (
    Select OrderID From Orders
    Except
    Select OrderID From FactOrders
    )
    Insert Into FactOrders(OrderID, OrderDate, CustomerId)
    Select OrderID, OrderDate, CustomerId From Orders
    Where OrderID in (Select OrderID from NewOrders);


    Say the query is run for the first time and Orders contains 400 million rows or more:



    Can SQL Server handle this number of rows in one single INSERT statement?



    If not, how should I proceed? Should I limit the number of rows fetched in the INSERT statement? How many rows can the engine handle in a single INSERT statement?










    share|improve this question


























      up vote
      4
      down vote

      favorite
      1









      up vote
      4
      down vote

      favorite
      1






      1





      To illustrate my question, the following is a query detecting order's id which have not been inserted in a data warehouse and inserts them:



      With NewOrders 
      As
      (
      Select OrderID From Orders
      Except
      Select OrderID From FactOrders
      )
      Insert Into FactOrders(OrderID, OrderDate, CustomerId)
      Select OrderID, OrderDate, CustomerId From Orders
      Where OrderID in (Select OrderID from NewOrders);


      Say the query is run for the first time and Orders contains 400 million rows or more:



      Can SQL Server handle this number of rows in one single INSERT statement?



      If not, how should I proceed? Should I limit the number of rows fetched in the INSERT statement? How many rows can the engine handle in a single INSERT statement?










      share|improve this question















      To illustrate my question, the following is a query detecting order's id which have not been inserted in a data warehouse and inserts them:



      With NewOrders 
      As
      (
      Select OrderID From Orders
      Except
      Select OrderID From FactOrders
      )
      Insert Into FactOrders(OrderID, OrderDate, CustomerId)
      Select OrderID, OrderDate, CustomerId From Orders
      Where OrderID in (Select OrderID from NewOrders);


      Say the query is run for the first time and Orders contains 400 million rows or more:



      Can SQL Server handle this number of rows in one single INSERT statement?



      If not, how should I proceed? Should I limit the number of rows fetched in the INSERT statement? How many rows can the engine handle in a single INSERT statement?







      sql-server t-sql data-warehouse azure-sql-data-warehouse






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 16 hours ago









      George.Palacios

      2,168823




      2,168823










      asked 16 hours ago









      Jérôme Verstrynge

      64431223




      64431223






















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          16
          down vote



          accepted










          According to the documentation the only limitation on the number of rows stored per table is as below




          Limited only by available resources




          What local resources does this potentially include?




          • Memory

          • Space in the database data files to physically write the inserted data to

          • Space in the database log files

          • Space in TempDB (Data and log)


          As for how much a single SELECT statement can extract, I cannot find any documentation pertaining to this directly, but I would assume it is safe to take this to be exactly the same as the above.






          share|improve this answer






























            up vote
            2
            down vote













            There does not appear to be a row limit except as it relates to resources. If your SQL Server truly have enough resources to insert half a billion rows then it will do it. In the past, I have been faced with such resource constraints, so I would add a WHERE clause that limited the resultset. Or I would run the INSERT recursively with a TOP on the select.



            With NewOrders 
            As
            (
            Select OrderID From Orders
            Except
            Select OrderID From FactOrders
            )
            Insert Into FactOrders(OrderID, OrderDate, CustomerId)
            Select **TOP 1000000** OrderID, OrderDate, CustomerId
            From Orders
            Where OrderID in (Select OrderID from NewOrders);





            share|improve this answer










            New contributor




            user167159 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.


















              Your Answer








              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "182"
              };
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function() {
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled) {
              StackExchange.using("snippets", function() {
              createEditor();
              });
              }
              else {
              createEditor();
              }
              });

              function createEditor() {
              StackExchange.prepareEditor({
              heartbeatType: 'answer',
              convertImagesToLinks: false,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: null,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });














              draft saved

              draft discarded


















              StackExchange.ready(
              function () {
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f225003%2fhow-many-rows-can-sql-server-process-in-a-single-insert-statement-into-a-table%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes








              up vote
              16
              down vote



              accepted










              According to the documentation the only limitation on the number of rows stored per table is as below




              Limited only by available resources




              What local resources does this potentially include?




              • Memory

              • Space in the database data files to physically write the inserted data to

              • Space in the database log files

              • Space in TempDB (Data and log)


              As for how much a single SELECT statement can extract, I cannot find any documentation pertaining to this directly, but I would assume it is safe to take this to be exactly the same as the above.






              share|improve this answer



























                up vote
                16
                down vote



                accepted










                According to the documentation the only limitation on the number of rows stored per table is as below




                Limited only by available resources




                What local resources does this potentially include?




                • Memory

                • Space in the database data files to physically write the inserted data to

                • Space in the database log files

                • Space in TempDB (Data and log)


                As for how much a single SELECT statement can extract, I cannot find any documentation pertaining to this directly, but I would assume it is safe to take this to be exactly the same as the above.






                share|improve this answer

























                  up vote
                  16
                  down vote



                  accepted







                  up vote
                  16
                  down vote



                  accepted






                  According to the documentation the only limitation on the number of rows stored per table is as below




                  Limited only by available resources




                  What local resources does this potentially include?




                  • Memory

                  • Space in the database data files to physically write the inserted data to

                  • Space in the database log files

                  • Space in TempDB (Data and log)


                  As for how much a single SELECT statement can extract, I cannot find any documentation pertaining to this directly, but I would assume it is safe to take this to be exactly the same as the above.






                  share|improve this answer














                  According to the documentation the only limitation on the number of rows stored per table is as below




                  Limited only by available resources




                  What local resources does this potentially include?




                  • Memory

                  • Space in the database data files to physically write the inserted data to

                  • Space in the database log files

                  • Space in TempDB (Data and log)


                  As for how much a single SELECT statement can extract, I cannot find any documentation pertaining to this directly, but I would assume it is safe to take this to be exactly the same as the above.







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited 15 hours ago

























                  answered 16 hours ago









                  George.Palacios

                  2,168823




                  2,168823
























                      up vote
                      2
                      down vote













                      There does not appear to be a row limit except as it relates to resources. If your SQL Server truly have enough resources to insert half a billion rows then it will do it. In the past, I have been faced with such resource constraints, so I would add a WHERE clause that limited the resultset. Or I would run the INSERT recursively with a TOP on the select.



                      With NewOrders 
                      As
                      (
                      Select OrderID From Orders
                      Except
                      Select OrderID From FactOrders
                      )
                      Insert Into FactOrders(OrderID, OrderDate, CustomerId)
                      Select **TOP 1000000** OrderID, OrderDate, CustomerId
                      From Orders
                      Where OrderID in (Select OrderID from NewOrders);





                      share|improve this answer










                      New contributor




                      user167159 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                      Check out our Code of Conduct.






















                        up vote
                        2
                        down vote













                        There does not appear to be a row limit except as it relates to resources. If your SQL Server truly have enough resources to insert half a billion rows then it will do it. In the past, I have been faced with such resource constraints, so I would add a WHERE clause that limited the resultset. Or I would run the INSERT recursively with a TOP on the select.



                        With NewOrders 
                        As
                        (
                        Select OrderID From Orders
                        Except
                        Select OrderID From FactOrders
                        )
                        Insert Into FactOrders(OrderID, OrderDate, CustomerId)
                        Select **TOP 1000000** OrderID, OrderDate, CustomerId
                        From Orders
                        Where OrderID in (Select OrderID from NewOrders);





                        share|improve this answer










                        New contributor




                        user167159 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                        Check out our Code of Conduct.




















                          up vote
                          2
                          down vote










                          up vote
                          2
                          down vote









                          There does not appear to be a row limit except as it relates to resources. If your SQL Server truly have enough resources to insert half a billion rows then it will do it. In the past, I have been faced with such resource constraints, so I would add a WHERE clause that limited the resultset. Or I would run the INSERT recursively with a TOP on the select.



                          With NewOrders 
                          As
                          (
                          Select OrderID From Orders
                          Except
                          Select OrderID From FactOrders
                          )
                          Insert Into FactOrders(OrderID, OrderDate, CustomerId)
                          Select **TOP 1000000** OrderID, OrderDate, CustomerId
                          From Orders
                          Where OrderID in (Select OrderID from NewOrders);





                          share|improve this answer










                          New contributor




                          user167159 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.









                          There does not appear to be a row limit except as it relates to resources. If your SQL Server truly have enough resources to insert half a billion rows then it will do it. In the past, I have been faced with such resource constraints, so I would add a WHERE clause that limited the resultset. Or I would run the INSERT recursively with a TOP on the select.



                          With NewOrders 
                          As
                          (
                          Select OrderID From Orders
                          Except
                          Select OrderID From FactOrders
                          )
                          Insert Into FactOrders(OrderID, OrderDate, CustomerId)
                          Select **TOP 1000000** OrderID, OrderDate, CustomerId
                          From Orders
                          Where OrderID in (Select OrderID from NewOrders);






                          share|improve this answer










                          New contributor




                          user167159 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.









                          share|improve this answer



                          share|improve this answer








                          edited 8 hours ago









                          Mr.Brownstone

                          8,70422041




                          8,70422041






                          New contributor




                          user167159 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.









                          answered 8 hours ago









                          user167159

                          211




                          211




                          New contributor




                          user167159 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.





                          New contributor





                          user167159 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.






                          user167159 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.






























                              draft saved

                              draft discarded




















































                              Thanks for contributing an answer to Database Administrators Stack Exchange!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.





                              Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                              Please pay close attention to the following guidance:


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f225003%2fhow-many-rows-can-sql-server-process-in-a-single-insert-statement-into-a-table%23new-answer', 'question_page');
                              }
                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              Plaza Victoria

                              Puebla de Zaragoza

                              Musa