sys.fn_hadr_backup_is_preferred_replica (Transact-sql) sys.fn_hadr_backup_is_preferred_replica (Transact-SQL)

適用範圍:Applies to: 是SQL ServerSQL Server (所有支援的版本) yesSQL ServerSQL Server (all supported versions) 適用範圍:Applies to: 是SQL ServerSQL Server (所有支援的版本) yesSQL ServerSQL Server (all supported versions)

用於判斷目前的複本是否為慣用的備份複本。Used to determine if the current replica is the preferred backup replica.

主題連結圖示 Transact-SQL 語法慣例Topic link icon Transact-SQL Syntax Conventions

語法Syntax

  
sys.fn_hadr_backup_is_preferred_replica ( 'dbname' )  

引數Arguments

'dbname''dbname'
這是要備份的資料庫名稱。Is the name of the database to be backed up. dbname 的類型為 sysname。dbname is type sysname.

傳回Returns

如果目前實例上的資料庫位於慣用複本,則傳回 bool:1資料類型,否則為0。Returns data type bool: 1 if the database on the current instance is on the preferred replica, otherwise 0.

備註Remarks

在備份指令碼中使用這個函數,以判斷目前的資料庫是否在備份所慣用的複本上。Use this function in a backup script to determine if the current database is on the replica that is preferred for backups. 您可以在每一個可用性複本上執行指令碼。You can run a script on every availability replica. 每一個作業都會查看相同的資料,以判斷應該執行哪一個作業,如此一來,只有其中一個排程作業會實際進行到備份階段。Each of these jobs looks at the same data to determine which job should run, so only one of the scheduled jobs actually proceeds to the backup stage. 範例程式碼可能如下所示。Sample code could be similar to the following.

If sys.fn_hadr_backup_is_preferred_replica( @dbname ) <> 1   
BEGIN  
-- If this is not the preferred replica, exit (probably without error).  
END  
-- If this is the preferred replica, continue to do the backup.  
  

範例Examples

A.A. 使用 sys.fn_hadr_backup_is_preferred_replicaUsing sys.fn_hadr_backup_is_preferred_replica

如果目前資料庫是慣用的備份複本,下列範例會傳回 1。The following example returns 1 if the current database is the preferred backup replica.

SELECT sys.fn_hadr_backup_is_preferred_replica ('TestDB');  
GO  

另請參閱See Also

Always On 可用性群組函數 (Transact-sql) Always On Availability Groups Functions (Transact-SQL)
AlwaysOn 可用性群組 (SQL Server) Always On Availability Groups (SQL Server)
CREATE AVAILABILITY GROUP (Transact-SQL) CREATE AVAILABILITY GROUP (Transact-SQL)
ALTER AVAILABILITY GROUP (Transact-SQL) ALTER AVAILABILITY GROUP (Transact-SQL)
使用中次要:在次要複本上備份 (Always On 可用性群組) Always On 可用性群組的目錄檢視 (transact-sql) Active Secondaries: Backup on Secondary Replicas (Always On Availability Groups) Always On Availability Groups Catalog Views (Transact-SQL)