Remove database mirroring with SQLCMD

As an addition to my previous post, I just want to share this script to remove the database mirroring from a database with SQLCMD.  Again, make sure that you have activated the SQLCMD Mode in your management studio (Menu – Query – SQLCMD Mode).

Remark: The database on the mirror server will be removed.

/****DEFINE THE VARIABLES THAT ARE NECESSARY TO REMOVE SQL DATABASE MIRRORING***/
:setvar MYDATABASE [AdventureWorks2012]
:setvar PRINCIPAL SQLSRV01
:setvar MIRROR SQLSRV02

:CONNECT $(PRINCIPAL)
GO
ALTER DATABASE $(MYDATABASE) SET PARTNER OFF
GO
:CONNECT $(MIRROR)
GO
RESTORE DATABASE $(MYDATABASE) WITH RECOVERY
GO
DROP DATABASE $(MYDATABASE)
GO

Leave a Reply

Your email address will not be published. Required fields are marked *