Schedule Jobs:
Jobs are scheduled objects which will execute a sequence of stored statements at a particular time or at regular intervals. Considering a practical scenario like, I need to take a backup of my database at regular intervals (Daily at 12AM). How can I achieve it?
This can be achieved through jobs in sql server. I will take a very simple scenario of inserting a record in a table. This insert should happen on weekly basis (One time) with no end date. Let's see the step by step procedure to ahieve it.
Below is the table (I need to insert into this table),
Check your SQL Server agent or else start your agent (The easier way is go to your services window and search for your sql server agent and start it) . Under SQL Server Agent -> jobs -> right click and create the job. Provide the Name of your job and possible description. You can specify the owner the job too.
On clicking the new button in the above window, we will get the steps window. You can provide the step name and command to be executed.
After providing the command, you can check the syntax by clicking the parse button.
Go to the scheduled tab and you can schedule your job. A job may have multiple schedules.
Now, I am creating the job which recurrent/weekly once /only on sunday /Occurs at 12AM /Start date is today / No end date.
Goto the next tab "Alert" -> You can customize the message for the job failure or else you can take the existing alerts.

That's it. Your job is ready to go. On clicking the Jobs, you can see your new job.
Considering, I need to execute the job now. Just right click the job and click start job.
To check the activity of the job in the servers. Right click job activity monitor and check it.
select * from dbo.sysjobschedules - >This table will show the scheduled job details. Job name/next run date.



No comments:
Post a Comment