sys.fn_hadr_is_primary_replica (Transact-SQL) - SQL Server
https://docs.microsoft.com/en-us/sql/relational-databases/system-functions/sys-fn-hadr-is-primary-replica-transact-sql
Apr 12, 2022 · 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. Examples 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.
DA: 12 PA: 83 MOZ Rank: 83