Trying to use sp_stop_job
to stop a simple job that inserts data on a table when 100 rows were inserted I got confused to see the table end up with more than 100 rows every time.
Under the Remarks section of the sp_stop_job
doc it says:
sp_stop_job sends a stop signal to the database. Some processes can be stopped immediately and some must reach a stable point (or an entry point to the code path) before they can stop.
I don't understand what it means to reach a stable point (or an entry point to the code path) and I believe the job keeps inserting the data on the table because it is still reaching that stable point.
The code:
CREATE TABLE [dbo].[myStopJobTable](
[id] [int] NULL,
[nome] [varchar](50) NULL
);
I created a job with a step to execute the following code:
WHILE (1=1)
BEGIN
INSERT INTO MyLab.dbo.myStopJobTable
VALUES (1, 'Some Name');
IF ((SELECT COUNT(*) FROM myStopJobTable) = 100)
BEGIN
EXEC msdb.dbo.sp_stop_job N'JobToBeStopped';
END
END;
From that sample code I expected the job to stop before the row 101 is inserted, but it doesn't. By adding a BREAK
inside the IF
block the process is stopped before the insertion of row 101 happens, but in that case it's not the sp_stop_job
working.
I don't want a fix for the job, what I seek is to understand that stable point (or an entry point to the code path). What does it mean?