Agent Jobs

Automatically Failover All Database Mirrors With A Single Job (05 of 10)

JOB:  DATABASE MIRRORS – FAILOVER ALL MIRRORED DATABASES

Automatically Failover All Database Mirrors With A Single Job_05

STEP 5:  FAILOVER ALL MIRRORED DATABASES

Step logic:

 

use master;
set nocount on

declare
	@failover_mirror_databases	varchar(max) = ''
select
	@failover_mirror_databases	= @failover_mirror_databases + 
	'alter database [' + cast(DB_NAME(database_id) as varchar(255)) + '] set partner failover;' + char(10) + char(10)
from
	sys.database_mirroring
where
	mirroring_guid is not null
	and mirroring_role_desc = 'PRINCIPAL'

exec (@failover_mirror_databases)

https://mikesdatawork.wordpress.com/2015/10/29/automatically-failover-all-database-mirrors-with-a-single-job-06-of-10/

Advertisements

1 reply »

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s