How To Failover Mutliple Mirroring Databases in SQL Server

Published: 20 October 2022
on channel: MS SQL DBA Tech Support
988
22

declare @databasename nvarchar(255)
declare @alldatabases cursor

-- Only select principal databases (mirroring_role).
set @alldatabases = cursor for
select d.name
from sys.databases d, sys.database_mirroring m
where m.database_id = d.database_id
and m.mirroring_role_desc = 'PRINCIPAL'

-- Execute the failover.
open @alldatabases
fetch next from @alldatabases into @databasename
while @@FETCH_STATUS = 0
begin
print @databasename
exec('alter database [' + @databasename + '] set partner failover')
fetch next from @alldatabases into @databasename
end
close @alldatabases
deallocate @alldatabases


Watch video How To Failover Mutliple Mirroring Databases in SQL Server online, duration hours minute second in high quality that is uploaded to the channel MS SQL DBA Tech Support 20 October 2022. Share the link to the video on social media so that your subscribers and friends will also watch this video. This video clip has been viewed 988 times and liked it 22 visitors.