Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
sys.fn_hadr_is_primary_replica (Transact-SQL)

sys.fn_hadr_is_primary_replica (Transact-SQL)


Applies To: SQL Server 2014, SQL Server 2016 Preview

Used to determine if the current replica is the primary replica.

Applies to: SQL Server (SQL Server 2014 through current version).

Topic link icon Transact-SQL Syntax Conventions

sys.fn_hadr_is_primary_replica ( '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 
-- If this is not the primary replica, exit (probably without error).
-- 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');

Community Additions

© 2015 Microsoft