Monday 31 December 2018

Schedule a job in sql server which start when Sql server Agent is started

My requirement is to log the information whenever someone starts the SQL Server Agent. I have created a job and schedule this job when SQL server Agent start, this job will trigger and insert a record into the log table.
create table SQL_SERVER_AGENT_AUDIT
(ID int identity(1,1),
Server_name varchar(50),
SQL_Server_Agent_Start_Time datetime)

Now am creating a job
In steps tab I am writing the insert statement to insert a record into the Audit table.
  
Click ok and go to the Scheduling tab.
Click on the New button.

Provide the schedule name and select Schedule type as ‘Start Automatically when SQL Server Agent starts’. And click ok.
Now our new job created successfully.
  
Currently, SQL Server Agent is running. Now going to stop this after that I will start.
Record in the table
   
SQL server Agent disabled now
 
     
Now I am starting the SQL Server Agent.
Now SQL Server Agent is started.
     
 
This scheduled job executed successfully see the job history as well as the Audit table.
Audit table record.
   
Job execution history

 
 

Popular Posts