Export (0) Print
Expand All

sys.fn_hadr_is_primary_replica (Transact-SQL)

SQL Server 2014

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' )

'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.

A. Using sys.fn_hadr_is_primary_replica

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
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft