Professional Documents
Culture Documents
AlwaysOn - Master Control Job and Alert
AlwaysOn - Master Control Job and Alert
</config>'
BEGIN TRANSACTION
BEGIN
END;
IF EXISTS (SELECT * FROM msdb..sysjobs WHERE name = @MasterControlJobName)
BEGIN
END
READ_ONLY FORWARD_ONLY
FOR
FROM
, MIN(ag.role_desc) AS role_desc
, desired_state =
ELSE 0
END)
FROM msdb..sysjobs AS j
LEFT JOIN
SELECT
ConfigType = x.value(''(@type)[1]'',''varchar(10)'')
, EnableWhen = x.value(''(@enablewhen)[1]'',''varchar(10)'')
, DBName = x.value(''(@dbname)[1]'',''sysname'')
, ItemName = x.value(''(text())[1]'',''nvarchar(4000)'')
) AS Config
ON
LEFT JOIN (
) AS ag
CROSS APPLY
WHERE (Config.DBName IS NOT NULL OR ag.databasename IS NOT NULL) -- at least one combination
found
) AS q
ORDER BY job_name;
OPEN JobsToUpdate;
WHILE @@FETCH_STATUS = 0
BEGIN
END
CLOSE JobsToUpdate;
DEALLOCATE JobsToUpdate;'
BEGIN
RAISERROR(N'@CMD is empty!',16,1);
GOTO QuitWithRollback;
END
@enabled=1,
@notify_level_eventlog=0,
@notify_level_email=0,
@notify_level_netsend=0,
@notify_level_page=0,
@delete_level=0,
@description=N'Source: https://madeiradata.github.io/mssql-jobs-hadr',
@category_name=N'AlwaysOn',
@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=@CMD,
@database_name=N'master',
@flags=8
@enabled=1,
@freq_type=4,
@freq_interval=1,
@freq_subday_type=4,
@freq_subday_interval=60,
@freq_relative_interval=0,
@freq_recurrence_factor=0,
@active_start_date=20100101,
@active_end_date=99991231,
@active_start_time=0,
@active_end_time=235959
@enabled=1,
@freq_type=64,
@freq_interval=0,
@freq_subday_type=0,
@freq_subday_interval=0,
@freq_relative_interval=0,
@freq_recurrence_factor=0,
@active_start_date=20100101,
@active_end_date=99991231,
@active_start_time=0,
@active_end_time=235959
COMMIT TRANSACTION
BEGIN TRANSACTION
BEGIN
END
BEGIN
END
@enabled=1,
@message_id=1480,
@severity=0,
@delay_between_responses=0,
@include_event_description_in=0,
@job_id=@jobId;
COMMIT TRANSACTION
GOTO EndSave
QuitWithRollback:
EndSave: