17.06.2013 Views

Beginning Microsoft SQL Server 2008 ... - S3 Tech Training

Beginning Microsoft SQL Server 2008 ... - S3 Tech Training

Beginning Microsoft SQL Server 2008 ... - S3 Tech Training

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 19: Playing Administrator<br />

aware, however, that there are more robust options available for the more advanced user that can allow<br />

you to programmatically control many of the administration features via the <strong>SQL</strong> <strong>Server</strong> Management<br />

Objects (SMO) object model.<br />

Scheduling Jobs<br />

564<br />

Many of the tasks that we’ll go over in the remainder of the chapter can be scheduled. Scheduling jobs<br />

allows you to run tasks that place a load on the system at off-peak hours. It also ensures that you don’t<br />

forget to take care of things. From index rebuilds to backups, you’ll hear of horror stories over and over<br />

about shops that “forgot” to do that, or thought they had set up a scheduled job but never checked on it.<br />

If your background is in Windows <strong>Server</strong>, and you have scheduled other jobs using the Windows Scheduler<br />

service, you could utilize that scheduling engine to support <strong>SQL</strong> <strong>Server</strong>. Doing things all in the<br />

Windows Scheduler allows you to have everything in one place, but <strong>SQL</strong> <strong>Server</strong> has some more robust<br />

branching options.<br />

There are basically two terms to think about: Jobs and Tasks.<br />

❑ Tasks: These are single processes that are to be executed or a batch of commands that are to be<br />

run. Tasks are not independent. They exist only as members of jobs.<br />

❑ Jobs: These are a grouping of one or more tasks that should be run together. You can, however,<br />

set up dependencies and branching depending on the success or failure of individual tasks. (For<br />

example, Task A runs if the previous task succeeds, but Task B runs if the previous task fails.)<br />

Jobs can be scheduled based on the following criteria:<br />

❑ Daily, weekly, or monthly basis<br />

❑ A specific time of the day<br />

❑ A specific frequency (say, every 10 minutes, or every hour)<br />

❑ When the CPU becomes idle for a period of time<br />

❑ When the <strong>SQL</strong> <strong>Server</strong> Agent starts<br />

❑ In response to an alert<br />

Tasks are run by virtue of being part of a job and based on the branching rules you define for your job.<br />

Just because a job runs doesn’t mean that all the tasks that are part of that job will run; some may be executed<br />

and others not depending on the success or failure of previous tasks in the job and what branching<br />

rules you have established. <strong>SQL</strong> <strong>Server</strong> not only allows one task to fire automatically when another finishes,<br />

it also allows for doing something entirely different (such as running some sort of recovery task) if<br />

the current task fails.<br />

In addition to branching you can, depending on what happens, also tell <strong>SQL</strong> <strong>Server</strong> to perform the following:<br />

❑ Provide notification of the success or failure of a job to an operator. You’re allowed to send a<br />

separate notification for a network message (which would pop up on a user’s screen as long as<br />

they are logged in), a pager, and an e-mail address to one operator each.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!