SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 

Get your favorite SSC scripts directly in SSMS with the free SQL Scripts addin. Search for scripts directly from SSMS, and instantly access any saved scripts in your SSC briefcase from the favorites tab.
Download now (direct download link)

SQL Procedure for adding Database in existing Always-On HADR.

By SQL Master,

There are two procedures which will be used  as :

1. Procedure 'usp_db_restore' is used for restore database on each replica associated with Always-On HADR (Secondery replicas). This procedure will be used internally in my next procedure to add database in Always-On.

/****************************************************************************
Procedure Name : usp_db_restore
Objective : This procedure is used for Database resoration in norecovery mode which will be used in procedure for adding databases in existing HADR Always-On.
Author : Rahul Biswas
Create Date : Rahul Biswas
Modified By : Rahul Biswas
Modified Date : 31th AUG 2017
Modifications :
--exec msdb.dbo.usp_db_restore 'rahulnew', 'c:\test\Rahul\', 'B','c:\test\Rahul\','c:\test\Rahul\'
--exec msdb.dbo.usp_db_restore 'DatabaseName', 'BackupPath', 'BackupType','DatafilePath(Includes.mdf and .ndf)','LogFilePath'
--The backup types are: B = Full Backup, D = Differential Backup, L = Log Backup
*****************************************************************************/
2. Procedure 'usp_hadr_add_database' is used for adding database in Always-On. Linked server of each secondary replica is required with same name as sql server name on primary replica..
/****************************************************************************
Procedure Name : usp_hadr_add_database
Objective : This procedure is used for Adding database in HADR Always-On Configuration
Author : Rahul Biswas
Create Date : Rahul Biswas
Modified By : Rahul Biswas
Modified Date : 31th AUG 2017
Modifications :
prerequisite : Linked server of each secondary replica is required with same name as sql server name on primary replica.
Example : EXEC MSDB.DBO.usp_hadr_add_database 'AG_TEST','RAHUL','\\TEST\TEST\','\\TEST\TEST\','D:\TEST\','D:\TEST\'
Example : EXEC MSDB.DBO.usp_hadr_add_database 'AvailibiltyGroupName','DBName','FullBackupPath','TransactionLogBackupPath','DataFilePath(Includes .mdf and .ndf)','LogFilepath'
*****************************************************************************/

Total article views: 161 | Views in the last 30 days: 161
 
Related Articles
SCRIPT

Database Restoration SQL Procedure for SQL Server 2014.

Database Restoration SQL Procedure 2014.

ARTICLE

The Connection to the Primary Replica is not Active

In this article, I’m going to talk an issue that I found when joining replica or database on seconda...

BLOG

The Connection to the Primary Replica is not Active

In this post, I’m going to talk an issue that I found when joining replica or database on secondar...

BLOG

Where Is My Primary Replica Again?

We have many clients with multi-node Availability Groups - that is, AGs with more than two replicas....

FORUM

stored procedures in a database

stored procedures in a database

 
Contribute