SQL Server – How to trigger a process to stop SQL Agent Job when data insertion happened in a table – SQL Circuit

SQL Server – How to trigger a process to stop SQL Agent Job when data insertion happened in a table

To trigger a process after insertion, we need to create INSERT trigger which trigger the process once data insert into table. 

Following are step(s):
1) Create a INSERT trigger on table
2) In the trigger definition, write the logic to stop the SQL Agent Job(s) based on Insertion if it is running.

USE msdb;
GO

IF EXISTS (
		SELECT 1
		FROM INSERTED
		)
BEGIN
	EXEC dbo.sp_stop_job N'YourJobName';
END
GO

Leave a Reply

Your email address will not be published. Required fields are marked *