| title | sys.fn_hadr_is_primary_replica (Transact-SQL) | Microsoft Docs | ||||
|---|---|---|---|---|---|
| ms.custom | |||||
| ms.date | 03/17/2017 | ||||
| ms.prod | sql | ||||
| ms.prod_service | database-engine | ||||
| ms.reviewer | |||||
| ms.technology | system-objects | ||||
| ms.topic | language-reference | ||||
| f1_keywords |
|
||||
| dev_langs |
|
||||
| helpviewer_keywords |
|
||||
| ms.assetid | c9b1969f-be1d-4dfb-a33d-551f380b9e27 | ||||
| author | MikeRayMSFT | ||||
| ms.author | mikeray |
[!INCLUDEtsql-appliesto-ss2014-xxxx-xxxx-xxx-md]
Used to determine if the current replica is the primary replica.
Transact-SQL Syntax Conventions
sys.fn_hadr_is_primary_replica ( 'dbname' )
'dbname'
Is the name of the database. dbname is type sysname.
Returns 1 if the database on the current instance is the primary replica. Otherwise returns 0.
Use this function to conveniently determine whether the local instance is hosting the primary replica of the specified availability database. Sample code could be similar to the following.
If sys.fn_hadr_is_primary_replica ( @dbname ) <> 1
BEGIN
-- If this is not the primary replica, exit (probably without error).
END
-- If this is the primary replica, continue to do the backup.
The following example returns 1 if the specified database on the local instance is the primary replica.
SELECT sys.fn_hadr_is_primary_replica ('TestDB');
GO
AlwaysOn Availability Groups Functions (Transact-SQL)
AlwaysOn Availability Groups (SQL Server)
CREATE AVAILABILITY GROUP (Transact-SQL)
ALTER AVAILABILITY GROUP (Transact-SQL)
AlwaysOn Availability Groups Catalog Views (Transact-SQL)