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












5














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





























    5














    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



























      5












      5








      5


      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 Dec 14 '18 at 14:27









      George.Palacios

      2,178824




      2,178824










      asked Dec 14 '18 at 14:05









      Jérôme Verstrynge

      65131223




      65131223






















          2 Answers
          2






          active

          oldest

          votes


















          17














          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































            3














            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























              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',
              autoActivateHeartbeat: false,
              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









              17














              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




























                17














                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


























                  17












                  17








                  17






                  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 Dec 14 '18 at 14:43

























                  answered Dec 14 '18 at 14:22









                  George.Palacios

                  2,178824




                  2,178824

























                      3














                      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




























                        3














                        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


























                          3












                          3








                          3






                          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














                          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














                          share|improve this answer



                          share|improve this answer








                          edited Dec 14 '18 at 22:29









                          Mr.Brownstone

                          8,87432241




                          8,87432241










                          answered Dec 14 '18 at 22:24









                          user167159

                          311




                          311






























                              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

                              Biblatex bibliography style without URLs when DOI exists (in Overleaf with Zotero bibliography)

                              ComboBox Display Member on multiple fields

                              Is it possible to collect Nectar points via Trainline?