Best way to run a large number of update queries by 1000 queries at a time









up vote
3
down vote

favorite












I have a SQL Server file with 50,000 update queries like this:



UPDATE [dbo].[TABLE1] SET [COLUMN2] = 'abc123' WHERE [Id] = 100;
UPDATE [dbo].[TABLE1] SET [COLUMN2] = 'def456' WHERE [Id] = 101;
UPDATE [dbo].[TABLE1] SET [COLUMN2] = 'ghi789' WHERE [Id] = 205;
UPDATE [dbo].[TABLE1] SET [COLUMN2] = 'jkl012' WHERE [Id] = 216;
UPDATE [dbo].[TABLE1] SET [COLUMN2] = 'mno345' WHERE [Id] = 350;


I don't want to run this file and execute all 50,000 queries at once.
What is the best way to do this by executing 1000 queries at a time, and when these are done move on to the next 1000 until all are executed?
Also If I get an error how would I do a rollback?










share|improve this question

















  • 3




    Create a memory variable table with all the data you want to update. They to an update on a join of that table. See: stackoverflow.com/questions/1604091/…
    – James A Mohler
    Nov 9 at 0:10











  • how many rows you need to update ?
    – Squirrel
    Nov 9 at 0:13










  • Could you please clarify why don't you want to run the whole file? I mean what is the reason, because knowing the reason will most probably drive to right answer.
    – Serg
    Nov 9 at 15:49














up vote
3
down vote

favorite












I have a SQL Server file with 50,000 update queries like this:



UPDATE [dbo].[TABLE1] SET [COLUMN2] = 'abc123' WHERE [Id] = 100;
UPDATE [dbo].[TABLE1] SET [COLUMN2] = 'def456' WHERE [Id] = 101;
UPDATE [dbo].[TABLE1] SET [COLUMN2] = 'ghi789' WHERE [Id] = 205;
UPDATE [dbo].[TABLE1] SET [COLUMN2] = 'jkl012' WHERE [Id] = 216;
UPDATE [dbo].[TABLE1] SET [COLUMN2] = 'mno345' WHERE [Id] = 350;


I don't want to run this file and execute all 50,000 queries at once.
What is the best way to do this by executing 1000 queries at a time, and when these are done move on to the next 1000 until all are executed?
Also If I get an error how would I do a rollback?










share|improve this question

















  • 3




    Create a memory variable table with all the data you want to update. They to an update on a join of that table. See: stackoverflow.com/questions/1604091/…
    – James A Mohler
    Nov 9 at 0:10











  • how many rows you need to update ?
    – Squirrel
    Nov 9 at 0:13










  • Could you please clarify why don't you want to run the whole file? I mean what is the reason, because knowing the reason will most probably drive to right answer.
    – Serg
    Nov 9 at 15:49












up vote
3
down vote

favorite









up vote
3
down vote

favorite











I have a SQL Server file with 50,000 update queries like this:



UPDATE [dbo].[TABLE1] SET [COLUMN2] = 'abc123' WHERE [Id] = 100;
UPDATE [dbo].[TABLE1] SET [COLUMN2] = 'def456' WHERE [Id] = 101;
UPDATE [dbo].[TABLE1] SET [COLUMN2] = 'ghi789' WHERE [Id] = 205;
UPDATE [dbo].[TABLE1] SET [COLUMN2] = 'jkl012' WHERE [Id] = 216;
UPDATE [dbo].[TABLE1] SET [COLUMN2] = 'mno345' WHERE [Id] = 350;


I don't want to run this file and execute all 50,000 queries at once.
What is the best way to do this by executing 1000 queries at a time, and when these are done move on to the next 1000 until all are executed?
Also If I get an error how would I do a rollback?










share|improve this question













I have a SQL Server file with 50,000 update queries like this:



UPDATE [dbo].[TABLE1] SET [COLUMN2] = 'abc123' WHERE [Id] = 100;
UPDATE [dbo].[TABLE1] SET [COLUMN2] = 'def456' WHERE [Id] = 101;
UPDATE [dbo].[TABLE1] SET [COLUMN2] = 'ghi789' WHERE [Id] = 205;
UPDATE [dbo].[TABLE1] SET [COLUMN2] = 'jkl012' WHERE [Id] = 216;
UPDATE [dbo].[TABLE1] SET [COLUMN2] = 'mno345' WHERE [Id] = 350;


I don't want to run this file and execute all 50,000 queries at once.
What is the best way to do this by executing 1000 queries at a time, and when these are done move on to the next 1000 until all are executed?
Also If I get an error how would I do a rollback?







sql sql-server tsql






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 9 at 0:06









user3067761

32115




32115







  • 3




    Create a memory variable table with all the data you want to update. They to an update on a join of that table. See: stackoverflow.com/questions/1604091/…
    – James A Mohler
    Nov 9 at 0:10











  • how many rows you need to update ?
    – Squirrel
    Nov 9 at 0:13










  • Could you please clarify why don't you want to run the whole file? I mean what is the reason, because knowing the reason will most probably drive to right answer.
    – Serg
    Nov 9 at 15:49












  • 3




    Create a memory variable table with all the data you want to update. They to an update on a join of that table. See: stackoverflow.com/questions/1604091/…
    – James A Mohler
    Nov 9 at 0:10











  • how many rows you need to update ?
    – Squirrel
    Nov 9 at 0:13










  • Could you please clarify why don't you want to run the whole file? I mean what is the reason, because knowing the reason will most probably drive to right answer.
    – Serg
    Nov 9 at 15:49







3




3




Create a memory variable table with all the data you want to update. They to an update on a join of that table. See: stackoverflow.com/questions/1604091/…
– James A Mohler
Nov 9 at 0:10





Create a memory variable table with all the data you want to update. They to an update on a join of that table. See: stackoverflow.com/questions/1604091/…
– James A Mohler
Nov 9 at 0:10













how many rows you need to update ?
– Squirrel
Nov 9 at 0:13




how many rows you need to update ?
– Squirrel
Nov 9 at 0:13












Could you please clarify why don't you want to run the whole file? I mean what is the reason, because knowing the reason will most probably drive to right answer.
– Serg
Nov 9 at 15:49




Could you please clarify why don't you want to run the whole file? I mean what is the reason, because knowing the reason will most probably drive to right answer.
– Serg
Nov 9 at 15:49












3 Answers
3






active

oldest

votes

















up vote
3
down vote













You should create a temporary table with the values. You can then use this for the update. Absent that, you can create a derived table in the query:



with t as (
select v.*
from (values (100, 'abc123'),
(200, 'def456'),
. . .
) v(id, column2)
)
update t1
set column2 = t.column2
from dbo.table1 t1 join
t
on t1.id = t.id;





share|improve this answer




















  • I was going to suggest the same, except use a temporary table and inserts, instead of a CTE
    – e_i_pi
    Nov 9 at 0:19

















up vote
2
down vote













use CASE WHEN statement



UPDATE [dbo].[TABLE1] 
SET [COLUMN2] = CASE [Id]
WHEN 100 THEN 'abc123'
WHEN 101 THEN 'def456'
WHEN 205 THEN 'ghi789'
WHEN 216 THEN 'jkl012'
WHEN 350 THEN 'mno345'
END
WHERE [Id] IN ( 100 , 101, 205, 216, 350 )





share|improve this answer



























    up vote
    1
    down vote













    You can try to use UNION ALL create a result set and write row number for it then do UPDATE .... JOIN.




    What is the best way to do this by executing 1000 queries at a time?




    If you want to update date for 1000 batch you can try to use loop (while) with variables to control.



    DECLARE @fromNum int = 1;
    DECLARE @toNum int = 1000;
    DECLARE @totalRowNum int;

    ;with cte as (
    SELECT 'abc123' COLUMN2,100 ID
    UNION ALL
    SELECT 'def456' ,101
    UNION ALL
    SELECT 'ghi789' ,205
    UNION ALL
    SELECT 'jkl012' ,216
    UNION ALL
    SELECT 'mno345' ,350
    ), cteRowNum as(
    SELECT *,ROW_NUMBER() OVER(ORDER BY (SELECT ID)) rn
    FROM cte
    )
    SELECT *
    INTO #Temp
    FROM cteRowNum

    SELECT @totalRowNum = MAX(rn)
    FROM #Temp

    While(@toNum < @totalRowNum)
    BEGIN
    BEGIN TRY
    BEGIN TRAN
    update t1
    set t1.COLUMN2 = t2.COLUMN2
    from TABLE1 t1 join #Temp t2 on t1.id = t2.ID
    where t2.rn between @fromNum and @toNum
    COMMIT TRAN
    END TRY
    BEGIN CATCH
     ROLLBACK TRAN
     SELECT ERROR_NUMBER() AS ErrorNumber,ERROR_SEVERITY() AS ErrorSeverity,ERROR_STATE() AS ErrorState,ERROR_PROCEDURE() AS ErrorProcedure,ERROR_LINE() AS ErrorLine,ERROR_MESSAGE() AS ErrorMessage
    END CATCH

    SET @fromNum = @toNum
    SET @toNum = @toNum + 1000
    END

    IF OBJECT_ID('dbo.Scores', 'U') IS NOT NULL
    DROP TABLE #Temp





    share|improve this answer






















    • This looks like it could work. I'm trying to test this, but I'm getting this error: Invalid object name 'cteRowNum' in the line from Table1 t1 join cteRowNum t2 on t1.id = t2.ID
      – user3067761
      Nov 9 at 20:18











    • @user3067761 I edit my answer you can try it, the problem is CTE can only use in next query so I use select .... insert into a temp table .
      – D-Shih
      Nov 9 at 22:36










    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    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: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    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%2fstackoverflow.com%2fquestions%2f53217987%2fbest-way-to-run-a-large-number-of-update-queries-by-1000-queries-at-a-time%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    3
    down vote













    You should create a temporary table with the values. You can then use this for the update. Absent that, you can create a derived table in the query:



    with t as (
    select v.*
    from (values (100, 'abc123'),
    (200, 'def456'),
    . . .
    ) v(id, column2)
    )
    update t1
    set column2 = t.column2
    from dbo.table1 t1 join
    t
    on t1.id = t.id;





    share|improve this answer




















    • I was going to suggest the same, except use a temporary table and inserts, instead of a CTE
      – e_i_pi
      Nov 9 at 0:19














    up vote
    3
    down vote













    You should create a temporary table with the values. You can then use this for the update. Absent that, you can create a derived table in the query:



    with t as (
    select v.*
    from (values (100, 'abc123'),
    (200, 'def456'),
    . . .
    ) v(id, column2)
    )
    update t1
    set column2 = t.column2
    from dbo.table1 t1 join
    t
    on t1.id = t.id;





    share|improve this answer




















    • I was going to suggest the same, except use a temporary table and inserts, instead of a CTE
      – e_i_pi
      Nov 9 at 0:19












    up vote
    3
    down vote










    up vote
    3
    down vote









    You should create a temporary table with the values. You can then use this for the update. Absent that, you can create a derived table in the query:



    with t as (
    select v.*
    from (values (100, 'abc123'),
    (200, 'def456'),
    . . .
    ) v(id, column2)
    )
    update t1
    set column2 = t.column2
    from dbo.table1 t1 join
    t
    on t1.id = t.id;





    share|improve this answer












    You should create a temporary table with the values. You can then use this for the update. Absent that, you can create a derived table in the query:



    with t as (
    select v.*
    from (values (100, 'abc123'),
    (200, 'def456'),
    . . .
    ) v(id, column2)
    )
    update t1
    set column2 = t.column2
    from dbo.table1 t1 join
    t
    on t1.id = t.id;






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 9 at 0:17









    Gordon Linoff

    747k34285390




    747k34285390











    • I was going to suggest the same, except use a temporary table and inserts, instead of a CTE
      – e_i_pi
      Nov 9 at 0:19
















    • I was going to suggest the same, except use a temporary table and inserts, instead of a CTE
      – e_i_pi
      Nov 9 at 0:19















    I was going to suggest the same, except use a temporary table and inserts, instead of a CTE
    – e_i_pi
    Nov 9 at 0:19




    I was going to suggest the same, except use a temporary table and inserts, instead of a CTE
    – e_i_pi
    Nov 9 at 0:19












    up vote
    2
    down vote













    use CASE WHEN statement



    UPDATE [dbo].[TABLE1] 
    SET [COLUMN2] = CASE [Id]
    WHEN 100 THEN 'abc123'
    WHEN 101 THEN 'def456'
    WHEN 205 THEN 'ghi789'
    WHEN 216 THEN 'jkl012'
    WHEN 350 THEN 'mno345'
    END
    WHERE [Id] IN ( 100 , 101, 205, 216, 350 )





    share|improve this answer
























      up vote
      2
      down vote













      use CASE WHEN statement



      UPDATE [dbo].[TABLE1] 
      SET [COLUMN2] = CASE [Id]
      WHEN 100 THEN 'abc123'
      WHEN 101 THEN 'def456'
      WHEN 205 THEN 'ghi789'
      WHEN 216 THEN 'jkl012'
      WHEN 350 THEN 'mno345'
      END
      WHERE [Id] IN ( 100 , 101, 205, 216, 350 )





      share|improve this answer






















        up vote
        2
        down vote










        up vote
        2
        down vote









        use CASE WHEN statement



        UPDATE [dbo].[TABLE1] 
        SET [COLUMN2] = CASE [Id]
        WHEN 100 THEN 'abc123'
        WHEN 101 THEN 'def456'
        WHEN 205 THEN 'ghi789'
        WHEN 216 THEN 'jkl012'
        WHEN 350 THEN 'mno345'
        END
        WHERE [Id] IN ( 100 , 101, 205, 216, 350 )





        share|improve this answer












        use CASE WHEN statement



        UPDATE [dbo].[TABLE1] 
        SET [COLUMN2] = CASE [Id]
        WHEN 100 THEN 'abc123'
        WHEN 101 THEN 'def456'
        WHEN 205 THEN 'ghi789'
        WHEN 216 THEN 'jkl012'
        WHEN 350 THEN 'mno345'
        END
        WHERE [Id] IN ( 100 , 101, 205, 216, 350 )






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 9 at 0:11









        Squirrel

        11.6k22027




        11.6k22027




















            up vote
            1
            down vote













            You can try to use UNION ALL create a result set and write row number for it then do UPDATE .... JOIN.




            What is the best way to do this by executing 1000 queries at a time?




            If you want to update date for 1000 batch you can try to use loop (while) with variables to control.



            DECLARE @fromNum int = 1;
            DECLARE @toNum int = 1000;
            DECLARE @totalRowNum int;

            ;with cte as (
            SELECT 'abc123' COLUMN2,100 ID
            UNION ALL
            SELECT 'def456' ,101
            UNION ALL
            SELECT 'ghi789' ,205
            UNION ALL
            SELECT 'jkl012' ,216
            UNION ALL
            SELECT 'mno345' ,350
            ), cteRowNum as(
            SELECT *,ROW_NUMBER() OVER(ORDER BY (SELECT ID)) rn
            FROM cte
            )
            SELECT *
            INTO #Temp
            FROM cteRowNum

            SELECT @totalRowNum = MAX(rn)
            FROM #Temp

            While(@toNum < @totalRowNum)
            BEGIN
            BEGIN TRY
            BEGIN TRAN
            update t1
            set t1.COLUMN2 = t2.COLUMN2
            from TABLE1 t1 join #Temp t2 on t1.id = t2.ID
            where t2.rn between @fromNum and @toNum
            COMMIT TRAN
            END TRY
            BEGIN CATCH
             ROLLBACK TRAN
             SELECT ERROR_NUMBER() AS ErrorNumber,ERROR_SEVERITY() AS ErrorSeverity,ERROR_STATE() AS ErrorState,ERROR_PROCEDURE() AS ErrorProcedure,ERROR_LINE() AS ErrorLine,ERROR_MESSAGE() AS ErrorMessage
            END CATCH

            SET @fromNum = @toNum
            SET @toNum = @toNum + 1000
            END

            IF OBJECT_ID('dbo.Scores', 'U') IS NOT NULL
            DROP TABLE #Temp





            share|improve this answer






















            • This looks like it could work. I'm trying to test this, but I'm getting this error: Invalid object name 'cteRowNum' in the line from Table1 t1 join cteRowNum t2 on t1.id = t2.ID
              – user3067761
              Nov 9 at 20:18











            • @user3067761 I edit my answer you can try it, the problem is CTE can only use in next query so I use select .... insert into a temp table .
              – D-Shih
              Nov 9 at 22:36














            up vote
            1
            down vote













            You can try to use UNION ALL create a result set and write row number for it then do UPDATE .... JOIN.




            What is the best way to do this by executing 1000 queries at a time?




            If you want to update date for 1000 batch you can try to use loop (while) with variables to control.



            DECLARE @fromNum int = 1;
            DECLARE @toNum int = 1000;
            DECLARE @totalRowNum int;

            ;with cte as (
            SELECT 'abc123' COLUMN2,100 ID
            UNION ALL
            SELECT 'def456' ,101
            UNION ALL
            SELECT 'ghi789' ,205
            UNION ALL
            SELECT 'jkl012' ,216
            UNION ALL
            SELECT 'mno345' ,350
            ), cteRowNum as(
            SELECT *,ROW_NUMBER() OVER(ORDER BY (SELECT ID)) rn
            FROM cte
            )
            SELECT *
            INTO #Temp
            FROM cteRowNum

            SELECT @totalRowNum = MAX(rn)
            FROM #Temp

            While(@toNum < @totalRowNum)
            BEGIN
            BEGIN TRY
            BEGIN TRAN
            update t1
            set t1.COLUMN2 = t2.COLUMN2
            from TABLE1 t1 join #Temp t2 on t1.id = t2.ID
            where t2.rn between @fromNum and @toNum
            COMMIT TRAN
            END TRY
            BEGIN CATCH
             ROLLBACK TRAN
             SELECT ERROR_NUMBER() AS ErrorNumber,ERROR_SEVERITY() AS ErrorSeverity,ERROR_STATE() AS ErrorState,ERROR_PROCEDURE() AS ErrorProcedure,ERROR_LINE() AS ErrorLine,ERROR_MESSAGE() AS ErrorMessage
            END CATCH

            SET @fromNum = @toNum
            SET @toNum = @toNum + 1000
            END

            IF OBJECT_ID('dbo.Scores', 'U') IS NOT NULL
            DROP TABLE #Temp





            share|improve this answer






















            • This looks like it could work. I'm trying to test this, but I'm getting this error: Invalid object name 'cteRowNum' in the line from Table1 t1 join cteRowNum t2 on t1.id = t2.ID
              – user3067761
              Nov 9 at 20:18











            • @user3067761 I edit my answer you can try it, the problem is CTE can only use in next query so I use select .... insert into a temp table .
              – D-Shih
              Nov 9 at 22:36












            up vote
            1
            down vote










            up vote
            1
            down vote









            You can try to use UNION ALL create a result set and write row number for it then do UPDATE .... JOIN.




            What is the best way to do this by executing 1000 queries at a time?




            If you want to update date for 1000 batch you can try to use loop (while) with variables to control.



            DECLARE @fromNum int = 1;
            DECLARE @toNum int = 1000;
            DECLARE @totalRowNum int;

            ;with cte as (
            SELECT 'abc123' COLUMN2,100 ID
            UNION ALL
            SELECT 'def456' ,101
            UNION ALL
            SELECT 'ghi789' ,205
            UNION ALL
            SELECT 'jkl012' ,216
            UNION ALL
            SELECT 'mno345' ,350
            ), cteRowNum as(
            SELECT *,ROW_NUMBER() OVER(ORDER BY (SELECT ID)) rn
            FROM cte
            )
            SELECT *
            INTO #Temp
            FROM cteRowNum

            SELECT @totalRowNum = MAX(rn)
            FROM #Temp

            While(@toNum < @totalRowNum)
            BEGIN
            BEGIN TRY
            BEGIN TRAN
            update t1
            set t1.COLUMN2 = t2.COLUMN2
            from TABLE1 t1 join #Temp t2 on t1.id = t2.ID
            where t2.rn between @fromNum and @toNum
            COMMIT TRAN
            END TRY
            BEGIN CATCH
             ROLLBACK TRAN
             SELECT ERROR_NUMBER() AS ErrorNumber,ERROR_SEVERITY() AS ErrorSeverity,ERROR_STATE() AS ErrorState,ERROR_PROCEDURE() AS ErrorProcedure,ERROR_LINE() AS ErrorLine,ERROR_MESSAGE() AS ErrorMessage
            END CATCH

            SET @fromNum = @toNum
            SET @toNum = @toNum + 1000
            END

            IF OBJECT_ID('dbo.Scores', 'U') IS NOT NULL
            DROP TABLE #Temp





            share|improve this answer














            You can try to use UNION ALL create a result set and write row number for it then do UPDATE .... JOIN.




            What is the best way to do this by executing 1000 queries at a time?




            If you want to update date for 1000 batch you can try to use loop (while) with variables to control.



            DECLARE @fromNum int = 1;
            DECLARE @toNum int = 1000;
            DECLARE @totalRowNum int;

            ;with cte as (
            SELECT 'abc123' COLUMN2,100 ID
            UNION ALL
            SELECT 'def456' ,101
            UNION ALL
            SELECT 'ghi789' ,205
            UNION ALL
            SELECT 'jkl012' ,216
            UNION ALL
            SELECT 'mno345' ,350
            ), cteRowNum as(
            SELECT *,ROW_NUMBER() OVER(ORDER BY (SELECT ID)) rn
            FROM cte
            )
            SELECT *
            INTO #Temp
            FROM cteRowNum

            SELECT @totalRowNum = MAX(rn)
            FROM #Temp

            While(@toNum < @totalRowNum)
            BEGIN
            BEGIN TRY
            BEGIN TRAN
            update t1
            set t1.COLUMN2 = t2.COLUMN2
            from TABLE1 t1 join #Temp t2 on t1.id = t2.ID
            where t2.rn between @fromNum and @toNum
            COMMIT TRAN
            END TRY
            BEGIN CATCH
             ROLLBACK TRAN
             SELECT ERROR_NUMBER() AS ErrorNumber,ERROR_SEVERITY() AS ErrorSeverity,ERROR_STATE() AS ErrorState,ERROR_PROCEDURE() AS ErrorProcedure,ERROR_LINE() AS ErrorLine,ERROR_MESSAGE() AS ErrorMessage
            END CATCH

            SET @fromNum = @toNum
            SET @toNum = @toNum + 1000
            END

            IF OBJECT_ID('dbo.Scores', 'U') IS NOT NULL
            DROP TABLE #Temp






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Nov 9 at 22:35

























            answered Nov 9 at 0:14









            D-Shih

            24.4k61431




            24.4k61431











            • This looks like it could work. I'm trying to test this, but I'm getting this error: Invalid object name 'cteRowNum' in the line from Table1 t1 join cteRowNum t2 on t1.id = t2.ID
              – user3067761
              Nov 9 at 20:18











            • @user3067761 I edit my answer you can try it, the problem is CTE can only use in next query so I use select .... insert into a temp table .
              – D-Shih
              Nov 9 at 22:36
















            • This looks like it could work. I'm trying to test this, but I'm getting this error: Invalid object name 'cteRowNum' in the line from Table1 t1 join cteRowNum t2 on t1.id = t2.ID
              – user3067761
              Nov 9 at 20:18











            • @user3067761 I edit my answer you can try it, the problem is CTE can only use in next query so I use select .... insert into a temp table .
              – D-Shih
              Nov 9 at 22:36















            This looks like it could work. I'm trying to test this, but I'm getting this error: Invalid object name 'cteRowNum' in the line from Table1 t1 join cteRowNum t2 on t1.id = t2.ID
            – user3067761
            Nov 9 at 20:18





            This looks like it could work. I'm trying to test this, but I'm getting this error: Invalid object name 'cteRowNum' in the line from Table1 t1 join cteRowNum t2 on t1.id = t2.ID
            – user3067761
            Nov 9 at 20:18













            @user3067761 I edit my answer you can try it, the problem is CTE can only use in next query so I use select .... insert into a temp table .
            – D-Shih
            Nov 9 at 22:36




            @user3067761 I edit my answer you can try it, the problem is CTE can only use in next query so I use select .... insert into a temp table .
            – D-Shih
            Nov 9 at 22:36

















             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53217987%2fbest-way-to-run-a-large-number-of-update-queries-by-1000-queries-at-a-time%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

            𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

            Edmonton

            Crossroads (UK TV series)