Click here to Skip to main content
14,268,822 members
   

Database

 
GeneralRe: Debug a procedure in Oracle which feeds into crystal report Pin
Member 1447460731-May-19 5:49
memberMember 1447460731-May-19 5:49 
GeneralRe: Debug a procedure in Oracle which feeds into crystal report Pin
Qingyong Yu16-Jul-19 18:51
memberQingyong Yu16-Jul-19 18:51 
NewsMessage Closed Pin
28-May-19 5:51
memberMember 1447108128-May-19 5:51 
QuestionCentOS6.9 (MySql v5.7.22) use mysql C API mysql_real_query cause the memory always growing Pin
normga23-May-19 3:13
membernormga23-May-19 3:13 
AnswerRe: CentOS6.9 (MySql v5.7.22) use mysql C API mysql_real_query cause the memory always growing Pin
jschell23-May-19 6:41
memberjschell23-May-19 6:41 
GeneralRe: CentOS6.9 (MySql v5.7.22) use mysql C API mysql_real_query cause the memory always growing Pin
normga23-May-19 9:27
membernormga23-May-19 9:27 
GeneralRe: CentOS6.9 (MySql v5.7.22) use mysql C API mysql_real_query cause the memory always growing Pin
jschell2-Jun-19 8:25
memberjschell2-Jun-19 8:25 
QuestionBest way to batchprocess a large update Pin
Jörgen Andersson23-May-19 2:09
protectorJörgen Andersson23-May-19 2:09 
So I need to regularly update a table with data from another table.
The problem is that if I update the normal way I get a table lock on the target table for half an hour, which is frowned upon by the users. So I need to run the update in batches.
The other problem is that the ID sequence is having gaps in it. Larger gaps than the batch size.
At the moment I have this solution:
DECLARE
        @LastID int = 0,
        @NextID int,
        @RC int = 1;
    
WHILE (@RC > 0)
BEGIN
    SELECT  TOP 5000
            @NextID = s.id
    FROM    Source s
    WHERE   s.id> @LastID
    ORDER BY s.id
    ;
    UPDATE  t
        SET  ------
    FROM    Source s
    JOIN    Target t ON t.id = s.id
    WHERE   s.id > @LastID 
        AND s.id <= @NextID 
    ;
    SET @RC = @@ROWCOUNT;
    SET @LastID = @NextID ;
END

Which works just fine, but using two selects is getting under my skin.

Any better suggestions for how to do it?
Wrong is evil and must be defeated. - Jeff Ello

AnswerRe: Best way to batchprocess a large update Pin
Richard Deeming23-May-19 7:38
mveRichard Deeming23-May-19 7:38 
GeneralRe: Best way to batchprocess a large update Pin
Jörgen Andersson23-May-19 7:52
protectorJörgen Andersson23-May-19 7:52 
GeneralRe: Best way to batchprocess a large update Pin
Jörgen Andersson23-May-19 22:08
protectorJörgen Andersson23-May-19 22:08 
GeneralRe: Best way to batchprocess a large update Pin
Richard Deeming24-May-19 0:44
mveRichard Deeming24-May-19 0:44 
GeneralRe: Best way to batchprocess a large update Pin
Jörgen Andersson24-May-19 1:45
protectorJörgen Andersson24-May-19 1:45 
GeneralRe: Best way to batchprocess a large update Pin
Jörgen Andersson26-May-19 23:17
protectorJörgen Andersson26-May-19 23:17 
AnswerRe: Best way to batchprocess a large update Pin
Eddy Vluggen24-May-19 0:04
mveEddy Vluggen24-May-19 0:04 
GeneralRe: Best way to batchprocess a large update Pin
Jörgen Andersson24-May-19 1:24
protectorJörgen Andersson24-May-19 1:24 
AnswerRe: Best way to batchprocess a large update Pin
#realJSOP29-May-19 0:43
mve#realJSOP29-May-19 0:43 
GeneralRe: Best way to batchprocess a large update Pin
Richard Deeming29-May-19 0:52
mveRichard Deeming29-May-19 0:52 
GeneralRe: Best way to batchprocess a large update Pin
#realJSOP29-May-19 1:06
mve#realJSOP29-May-19 1:06 
GeneralRe: Best way to batchprocess a large update Pin
Richard Deeming29-May-19 1:12
mveRichard Deeming29-May-19 1:12 
GeneralRe: Best way to batchprocess a large update Pin
#realJSOP29-May-19 1:20
mve#realJSOP29-May-19 1:20 
GeneralRe: Best way to batchprocess a large update Pin
Jörgen Andersson29-May-19 2:59
protectorJörgen Andersson29-May-19 2:59 
GeneralRe: Best way to batchprocess a large update Pin
#realJSOP29-May-19 5:13
mve#realJSOP29-May-19 5:13 
AnswerRe: Best way to batchprocess a large update Pin
#realJSOP29-May-19 1:14
mve#realJSOP29-May-19 1:14 
GeneralRe: Best way to batchprocess a large update Pin
Jörgen Andersson29-May-19 3:01
protectorJörgen Andersson29-May-19 3:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.