1. Trang chủ
  2. » Công Nghệ Thông Tin

Hướng dẫn học Microsoft SQL Server 2008 part 107 pdf

10 173 0
Tài liệu đã được kiểm tra trùng lặp

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 10
Dung lượng 720,34 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

This brings up the Manage Job Categories dialog, shown in Figure 43-8.. Enable it one of three ways: ■ From the Database Mail Configuration Wizard ■ With the sp_configure ‘Database Mail

Trang 1

FIGURE 43-7

Set the conditions that you consider equivalent to CPU idle time

Some wizards such as Maintenance Plan Wizard create jobs behind the scenes when you use them Any

form of replication also creates jobs behind the scenes

As with alerts, create a new job using the New Job dialog Creating a job involves five distinct steps:

1 Create a job definition.

2 Set each step to execute.

3 Set the next action for each step.

4 Configure a job schedule.

5 Handle completion-, success-, and failure-notification messages.

The following sections walk through each of these steps The first section that follows discusses the

optional step of creating a job category

Trang 2

Creating a job category

As you will see in the next section, when defining a job, you can assign a category to it This enables

you to group similar jobs together Here are the steps you can use to manage job categories:

1 Start SQL Server Management Studio.

2 Right-click the SQL Server Agent\Jobs folder and choose Manage Job Categories from the

context menu This brings up the Manage Job Categories dialog, shown in Figure 43-8

FIGURE 43-8

The Manage Job Categories dialog enables you to maintain the job categories used when you define

a new job

3 Create a new job category by clicking Add This brings up the New Category properties dialog.

4 Type a descriptive name for the category in the Name field.

5 Add jobs to this category by clicking the Show All Jobs check box and selecting the

cor-responding check box in the Select column of the job list Jobs that don’t have a category

assigned automatically appear in the list Selecting Show All Jobs will also reveal jobs that

already have a category assigned

1023

www.getcoolebook.com

Trang 3

6 The Manage Job Categories dialog is also the place to remove existing job categories Highlight

the job category to be deleted and click Delete

7 In addition, you can see a list of the jobs currently assigned to a particular category Highlight

the job category to view and click View Jobs Add additional jobs to a category by clicking the Show All Jobs check box and checking the job’s entry in the Select column of the New Job Category dialog

Creating a job definition

The main component of a job definition is the unique name that will be used to refer to the job Use

this unique name, for example, to specify which job to run when an alert is triggered Here’s how to

create a job definition:

1 Start SQL Server Management Studio and find the SQL Server Agent folder below the server

you are configuring

2 Expand the SQL Server Agent folder to see the items below it.

3 Right-click the Jobs folder and choose New Job from the context menu This brings up a New

Job dialog similar to the one shown in Figure 43-9

FIGURE 43-9

You can categorize and assign an owner to a new job in the New Job dialog

Trang 4

4 In the General tab, give the job a unique name (up to 128 characters), select an appropriate

category and owner for the job, and type a description of the job Only administrators can

change the owner of an existing job

Only predefined logins can be used as the owner If you do not find the login you want to

use, exit the job definition by clicking the Cancel button and create a login for the account

you want to use To do this, expand the Security folder in Management Studio, right-click on Logins, and

then select New Login.

5 Select the Targets folder Select the Target Local Server for jobs that run on a single, local

machine If job scheduling across multiple servers is configured, choose Target Multiple Servers

and select which servers acts as the target servers (the servers on which the job runs)

6 Click Apply to create the job definition You are now ready for the next steps, as explained in

the following sections

Setting up the job steps

After creating a job definition, the next step (if applicable) is to define what steps need to be performed

during the job Do this by clicking the Steps tab (see Figure 43-10) in the Job Properties dialog The

buttons on this screen are as follows:

FIGURE 43-10

A job may consist of one or more steps, which are created in the Steps tab

1025

www.getcoolebook.com

Trang 5

■ New: Creates a new step

■ Insert: Inserts a step before the currently highlighted step

■ Edit: Modifies the currently highlighted step

■ Delete: Deletes the currently highlighted step

■ Move step up: Moves the currently highlighted step up one in the list

■ Move step down: Moves the currently highlighted step down one in the list

■ Start step: Enables you to choose which step is executed first This first step is indicated by a green flag

When creating a new step, you are presented with the New Job Step dialog, shown in Figure 43-11

All steps require a unique name (up to 128 characters) For the three most common types of steps

(Transact-SQL Script, ActiveX script, and operating-system commands), simply type in the Command

box the code you want executed You may also click the Open button to load the code from a file The

Parse button enables you to check the syntax of the command

FIGURE 43-11

A step can execute any Transact-SQL code

Trang 6

After you have entered the code that should run for the step, you can click the Advanced tab (see

Figure 43-12) in the New Job Step dialog to specify what happens after the step executes You can also

specify how many times the step is attempted in case of initial failure, as well as the delay in minutes

between the attempts

FIGURE 43-12

Use the Advanced tab to control what happens after a step executes

Configuring a job schedule

After entering the steps for a given job, the next step is to specify when the job is to be executed, done

in the Schedules tab of the New Job dialog Clicking the New button on this tab brings up the New Job

Schedule dialog, shown in Figure 43-13

Many maintenance tasks are recurring jobs If you don’t like the default (every week on Sunday at

12:00:00A.M.), you can define how frequently the task is to be repeated Figure 43-13 shows there is

plenty of flexibility in scheduling a recurring job

1027

www.getcoolebook.com

Trang 7

FIGURE 43-13

Jobs can be scheduled on a one-time basis or on a recurring basis

Handling completion-, success-, and failure-notification

messages

Finally, click the Notifications tab (see Figure 43-14) of the New Job dialog to specify the type of

notifi-cation to be used when the job completes, fails, or succeeds You can send a message to an operator (via

e-mail, pager, or Net Send message), log the related event, automatically delete the step, or any

combi-nation of these

Database Mail

Starting with SQL Server 2005, Database Mail was introduced as an enterprise solution to send e-mails

from SQL Server Database Mail features many improvements over SQL Mail, the most important of

which is that it is no longer dependent on Messaging Application Program Interface (MAPI) It uses

Simple Mail Transfer Protocol (SMTP), and you do not need to install an extended MAPI client (for

example, Microsoft Outlook) on your production SQL Server to use Database Mail

Trang 8

FIGURE 43-14

You can specify the type of notification to be used when the job completes, fails, or succeeds

Here are some important advantages of Database Mail:

■ Database Mail works in the background It uses Service Broker queue for the messages,

providing asynchronous, out of process delivery

■ It can be configured to use more than one SMTP server, thereby eliminating single point of

failure

■ It is cluster aware and fully supported on SQL Server Failover Cluster

■ It is fully supported on 64-bit SQL Server installations

The SQL Mail feature still exists in Microsoft SQL Server 2008 for backward compatibility.

It is recommended to stop using SQL Mail and use Database Mail instead, as SQL Mail will

be removed in a future version of SQL Server.

Database Mail is not available in SQL Server Express Edition.

1029

www.getcoolebook.com

Trang 9

Configuring database mail

Configuring Database Mail is very simple compared to configuring SQL Mail Microsoft makes it easy by

providing a Database Mail Configuration Wizard

By default, Database Mail is not enabled Enable it one of three ways:

From the Database Mail Configuration Wizard

With the sp_configure ‘Database Mail XPs ’ option

Using the Surface Area Configuration Tool of policy-based management.

Configuring Database Mail involves the following distinct steps:

1 Enable Database Mail.

2 Create a Database Mail profile.

3 Create a Database Mail account.

4 Add the account to the profile.

5 Grant permission for a user or a role to use the Database Mail profile.

Using the Database Mail Configuration Wizard

The following section walks through each of these steps For configuring database mail for the first time,

it is best to use the Database Mail Configuration Wizard Follow these steps to configure Database Mail:

1 Open SQL Server Management Studio and find the Management folder under the SQL Server

you are configuring

2 Expand the Management folder, right-click the Database Mail folder and select Configure

Database Mail from the context menu This brings up the Database Mail Configuration Wizard

Clicking Next brings up the Select Configuration Task dialog, as shown in Figure 43-15

3 Because it’s the initial Database Mail setup, keep the default selection of Set up Database Mail

and click Next to continue Once you have configured Database Mail, you can select the other options to manage the Database Mail accounts and profiles, manage profile security, and view

or change Database Mail system parameters

4 Because Database Mail is not enabled by default, a dialog similar to the one shown in

Figure 43-16 pops up, asking you if you want to enable Database Mail

5 Click Yes (Alternately, Database Mail can be enabled by setting the ‘Database Mail XPs’

sp_configureoption to 1) Once Database Mail is enabled, the New Profile dialog will appear, as shown in Figure 43-17

6 Type a name for the Database Mail profile Click Add to create a Database Mail Account

and add it to the profile This brings up the New Database Mail Account dialog shown in Figure 43-18 You may have to get the information required for this dialog from your server and/or security team beforehand Enter the information, select the SMTP authentication, and click OK to continue

Trang 10

FIGURE 43-15

This handy wizard makes it easy to set up and manage Database Mail

FIGURE 43-16

Enable Database Mail feature

1031

www.getcoolebook.com

Ngày đăng: 04/07/2014, 09:20