SQL Server Tacklebox- P6: This book, as with almost all books, started out as an idea. I wanted to accumulate together those scripts and tools that I have built over the years so that DBAs could sort through them and perhaps adapt them for their own circumstances. | 1 Eating SQL Server installations for breakfast DECLARE @ReturnCode INT @jobId BINARY 16 @MyServer nvarchar 75 @SQL nvarchar 4000 @CR nvarchar 2 SELECT @ReturnCode 0 @CR char 13 char 10 IF NOT EXISTS SELECT name FROM WHERE name N Database Maintenance AND category_class 1 BEGIN EXEC @ReturnCode @class N JOB @type N LOCAL @name N Database Maintenance IF @@ERROR 0 OR @ReturnCode 0 Begin GOTO QuitWithRollback End END IF EXISTS SELECT name FROM WHERE name N IDX Maintenance AND category_id Select category_id From Where name Database Maintenance 25 1 Eating SQL Server installations for breakfast Begin Exec @job_name IDX Maintenance End EXEC @ReturnCode @job_name N IDX Maintenance @enabled 1 @notify_level_eventlog 0 @notify_level_email 0 @notify_level_netsend 0 @notify_level_page 0 @delete_level 0 @description N Index Tuning @category_name N Database Maintenance @owner_login_name @JobOwner @job_id @jobId OUTPUT IF @@ERROR 0 OR @ReturnCode 0 Begin GOTO QuitWithRollback End Select @SQL exec spxIDXMaint char 39 @DayToReindex char 39 EXEC @ReturnCode @job_id @jobId @step_name N Index Maintenance @step_id 1 @cmdexec_success_code 0 @on_success_action 1 @on_success_step_id 0 @on_fail_action 2 @on_fail_step_id 0 @retry_attempts 0 @retry_interval 0 @os_run_priority 0 @subsystem N TSQL @command @SQL @database_name N _DBAMain @flags 0 IF @@ERROR 0 OR @ReturnCode 0 26 1 Eating SQL Server installations for breakfast Begin GOTO QuitWithRollback End EXEC @ReturnCode @job_id @jobId @start_step_id 1 IF @@ERROR 0 OR @ReturnCode 0 Begin GOTO QuitWithRollback End EXEC @ReturnCode @job_id @jobId @notify_level_email 2 @notify_level_netsend 2 @notify_level_page 2 @notify_email_operator_name @ValidOperator IF @@ERROR 0 OR @ReturnCode 0 Begin GOTO QuitWithRollback End EXEC @ReturnCode .