ppk on JavaScript, 1/e

Maintenance plans are a common way to detect problems in your database, correct the problems, and perform full and transaction log backups. To create a maintenance plan in Enterprise Manager, right-click Database Maintenance Plans under the Management group and select New Maintenance Plan. This opens the Database Maintenance Plan Wizard, which walks you through creating a plan with easy-to-follow steps.

After you finish using the wizard, several jobs are created for each item that needs to be scheduled. The wizard also adds an entry in the Database Maintenance Plans section of Enterprise Manager. Enterprise Manager reads from the sysdbmaintplans in the msdb database.

To execute the maintenance plan, you must execute the individual jobs in Enterprise Manager or use the sqlmaint tool (discussed next). After you execute the maintenance plan, it is logged in the sysdbmaintplan_history table, which is also in the msdb database. The easiest way to view the information from this table is to right-click the maintenance plan and select Maintenance Plan History. You are shown how long each step of the maintenance plan took to execute and any resulting errors.

Tip 

To protect your maintenance plans, make sure you make regular backups of the msdb database.

Using sqlmaint

You can execute a maintenance plan from a command-line utility called sqlmaint, which is located in the \Program Files\Microsoft SQL Server\MSSQL\Binn directory. This utility allows you to execute some pieces of a maintenance plan without creating a plan at all. Here are some of the parameters you can use with this utility:

To execute a maintenance plan called 'DB Maintenance Plan1' using sqlmaint, you can use the following syntax:

sqlmaint -S xanadu -U "sa" -P "password" -PlanName "DB Maintenance Plan1" -BkUpDB -BkUpMedia DISK -UseDefDir -CrBkSubDir -DelBkUps 2weeks

Using xp_sqlmaint

You can also execute a maintenance plan from T-SQL using the xp_sqlmaint system extended stored procedure. To execute the stored procedure, call it and add any parameters in quotes as shown here:

master..xp_sqlmaint '-S xanadu -U "sa" -P "" -PlanName "DB Maintenance Plan1" -BkUpDB -BkUpMedia DISK -UseDefDir -CrBkSubDir -DelBkUps 2weeks'

Категории