mirror of
https://github.com/Microsoft/sql-server-samples.git
synced 2025-12-08 14:58:54 +00:00
Resubmit: Moving the batch commit to Stored Proc DailyProcssToCreateHistory
Reason: There are pre-looping data initialization and post-looping reintialization in Stored Proc DailyProcssToCreateHistory. If the batch commit is in 6-wwi-data-simulation.sql, there will be duplicated pre-loop initialization, security setting and wrong post-loop data initialization. Solution: Move the batch commit into DailyProcssToCreateHistory's WHILE loop. Known behavior: the day after 20151220 will trigger RecordColdRoomTemperatures, which is slow and it's my next work item.
This commit is contained in:
+19
-2
@@ -2926,7 +2926,9 @@ CREATE PROCEDURE DataLoadSimulation.DailyProcessToCreateHistory
|
||||
@SundayPercentageOfNormalWorkDay int,
|
||||
@UpdateCustomFields bit,
|
||||
@IsSilentMode bit,
|
||||
@AreDatesPrinted bit
|
||||
@AreDatesPrinted bit,
|
||||
-- @CommitBatchSize, the size of each commit batch, added by Shiyang Qiu, July 14, 2016
|
||||
@CommitBatchSize int = 10
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON;
|
||||
@@ -2941,6 +2943,8 @@ BEGIN
|
||||
DECLARE @IsMonday bit;
|
||||
DECLARE @Weekday int;
|
||||
DECLARE @IsStaffOnly bit;
|
||||
-- @TotalNumberCounter, used to count the number of record, added by Shiyang Qiu, July 14, 2016
|
||||
DECLARE @TotalNumberCounter int = 1;
|
||||
|
||||
SET DATEFIRST 7; -- Week begins on Sunday
|
||||
|
||||
@@ -2948,6 +2952,9 @@ BEGIN
|
||||
|
||||
WHILE @CurrentDateTime <= @EndDate
|
||||
BEGIN
|
||||
--begin tran if there is no transaction
|
||||
IF(@@TRANCOUNT=0) BEGIN TRAN
|
||||
|
||||
IF @AreDatesPrinted <> 0 OR @IsSilentMode = 0
|
||||
BEGIN
|
||||
PRINT SUBSTRING(DATENAME(weekday, @CurrentDateTime), 1,3) + N'' '' + CONVERT(nvarchar(20), @CurrentDateTime, 107);
|
||||
@@ -3088,7 +3095,17 @@ BEGIN
|
||||
PRINT N'' '';
|
||||
END;
|
||||
|
||||
SET @CurrentDateTime = DATEADD(day, 1, @CurrentDateTime);
|
||||
--control the batch commit
|
||||
--where there is tran, and (meet the commit size or the final record)
|
||||
IF(@@TRANCOUNT=1 and ((@TotalNumberCounter % @CommitBatchSize = 0) or @CurrentDateTime = @EndDate))
|
||||
BEGIN
|
||||
IF @AreDatesPrinted <> 0 OR @IsSilentMode = 0 print ''COMMIT''
|
||||
COMMIT
|
||||
END
|
||||
|
||||
-- increase the @CurrentDateTime and the @TotalNumberCounter
|
||||
SET @CurrentDateTime = DATEADD(day, 1, @CurrentDateTime);
|
||||
SET @TotalNumberCounter = @TotalNumberCounter + 1;
|
||||
END; -- of processing each day
|
||||
|
||||
IF @UpdateCustomFields <> 0
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user