sys.dm_operation_statussys.dm_operation_status

適用範圍:Applies to: 是Azure SQL DatabaseAzure SQL DatabaseYesAzure SQL DatabaseAzure SQL Database 是Azure SQL 受控執行個體Azure SQL Managed InstanceYesAzure SQL 受控執行個體Azure SQL Managed Instance 是Azure Synapse AnalyticsAzure Synapse AnalyticsyesAzure Synapse AnalyticsAzure Synapse Analytics適用範圍:Applies to: 是Azure SQL DatabaseAzure SQL DatabaseYesAzure SQL DatabaseAzure SQL Database 是Azure SQL 受控執行個體Azure SQL Managed InstanceYesAzure SQL 受控執行個體Azure SQL Managed Instance 是Azure Synapse AnalyticsAzure Synapse AnalyticsyesAzure Synapse AnalyticsAzure Synapse Analytics

傳回 Azure SQL DatabaseAzure SQL Database 伺服器中的資料庫上所執行之作業的相關資訊。Returns information about operations performed on databases in a Azure SQL DatabaseAzure SQL Database server.

資料行名稱Column Name 資料類型Data Type 描述Description
session_activity_idsession_activity_id uniqueidentifieruniqueidentifier 作業的識別碼。ID of the operation. 非 Null。Not null.
resource_typeresource_type intint 表示執行作業所在資源的類型。Denotes the type of resource on which the operation is performed. 非 Null。Not null. 在目前的版本中,這個檢視只會追蹤 SQL DatabaseSQL Database 上所執行的作業,對應的整數值為 0。In the current release, this view tracks operations performed on SQL DatabaseSQL Database only, and the corresponding integer value is 0.
resource_type_descresource_type_desc nvarchar(2048)nvarchar(2048) 執行作業所在的資源類型描述。Description of the resource type on which the operation is performed. 在目前的版本中,這個檢視只會追蹤 SQL DatabaseSQL Database 上所執行的作業。In the current release, this view tracks operations performed on SQL DatabaseSQL Database only.
major_resource_idmajor_resource_id sql_variantsql_variant 執行作業所在的 SQL DatabaseSQL Database 的名稱。Name of the SQL DatabaseSQL Database on which the operation is performed. 非 Null。Not Null.
minor_resource_idminor_resource_id sql_variantsql_variant 僅供內部使用。For internal use only. 非 Null。Not null.
作業operation nvarchar(60)nvarchar(60) SQL DatabaseSQL Database 上執行的運算,例如 CREATE 或 ALTER。Operation performed on a SQL DatabaseSQL Database, such as CREATE or ALTER.
statestate tinyinttinyint 作業的狀態。The state of the operation.

0 = 暫止0 = Pending
1 = 進行中1 = In progress
2 = 已完成2 = Completed
3 = 失敗3 = Failed
4 = 已取消4 = Cancelled
state_descstate_desc nvarchar(120)nvarchar(120) PENDING = 作業正在等候可用的資源或配額。PENDING = operation is waiting for resource or quota availability.

IN_PROGRESS = 作業已開始且正在進行。IN_PROGRESS = operation has started and is in progress.

COMPLETED = 作業已成功完成。COMPLETED = operation completed successfully.

FAILED = 作業失敗。FAILED = operation failed. 如需詳細資訊,請參閱 error_desc 資料行。See the error_desc column for details.

CANCELLED = 使用者要求停止作業。CANCELLED = operation stopped at the request of the user.
percent_completepercent_complete intint 已完成作業的百分比。Percentage of operation that has completed. 值不是連續的,而且有效值如下所示。Values are not continuous and the valid values are listed below. 不是 Null。Not NULL.

0 = 作業未啟動0 = Operation not started
50 = 操作進行中50 = Operation in progress
100 = 作業完成100 = Operation complete
error_codeerror_code intint 表示在作業失敗期間發生之錯誤的代碼。Code indicating the error that occurred during a failed operation. 如果這個值為 0,就表示作業已順利完成。If the value is 0, it indicates that the operation completed successfully.
error_descerror_desc nvarchar(2048)nvarchar(2048) 在作業失敗期間發生之錯誤的描述。Description of the error that occurred during a failed operation.
error_severityerror_severity intint 在作業失敗期間發生之錯誤的嚴重性層級。Severity level of the error that occurred during a failed operation. 如需有關錯誤嚴重性的詳細資訊,請參閱 資料庫引擎錯誤嚴重性For more information about error severities, see Database Engine Error Severities.
error_stateerror_state intint 保留供未來使用。Reserved for future use. 我們無法保證未來的相容性。Future compatibility is not guaranteed.
start_timestart_time datetimedatetime 作業啟動時的時間戳記。Timestamp when the operation started.
last_modify_timelast_modify_time datetimedatetime 上次修改長時間執行作業之記錄時的時間戳記。Timestamp when the record was last modified for a long running operation. 如果作業順利完成,這個欄位會顯示作業完成時的時間戳記。In case of successfully completed operations, this field displays the timestamp when the operation completed.

權限Permissions

只有 master 資料庫中的伺服器層級主體登入才能使用此視圖。This view is only available in the master database to the server-level principal login.

備註Remarks

若要使用此視圖,您必須連接到 master 資料庫。To use this view, you must be connected to the master database. sys.dm_operation_status 伺服器的 master 資料庫中,使用 view SQL DatabaseSQL Database 來追蹤在上執行的下列作業的狀態 SQL DatabaseSQL DatabaseUse the sys.dm_operation_status view in the master database of the SQL DatabaseSQL Database server to track the status of the following operations performed on a SQL DatabaseSQL Database:

  • 建立資料庫Create database

  • 複製資料庫。Copy database. 資料庫複製會在來源和目標伺服器的這個檢視中,建立一筆記錄。Database Copy creates a record in this view on both the source and target servers.

  • 改變資料庫Alter database

  • 變更服務層的效能層級Change the performance level of a service tier

  • 變更資料庫的服務層,例如從 Basic 變更為 Standard。Change the service tier of a database, such as changing from Basic to Standard.

  • 設定異地備援關聯性Setting up a Geo-Replication relationship

  • 終止異地備援關聯性Terminating a Geo-Replication relationship

  • 對話方塊的Restore database

  • 刪除資料庫Delete database

此視圖中的資訊大約會保留1小時。The information in this view is retained for approximately 1 hour. 請使用 Azure 活動記錄 來查看過去90天的作業詳細資料。Please use the Azure Activity Log to view details of operations in the last 90 days. 保留超過90天,請考慮將 活動記錄 專案傳送至 Log Analytics 工作區。For retention more than 90 days, consider sending Activity Log entries to a Log Analytics workspace.

範例Example

顯示與資料庫 ' mydb ' 相關聯的最新異地複寫作業。Show most recent geo-replication operations associated with database 'mydb'.

SELECT * FROM sys.dm_operation_status   
   WHERE major_resource_id = 'myddb'   
   ORDER BY start_time DESC;  

另請參閱See Also

異地複寫動態管理檢視和函式 (Azure SQL Database) Geo-Replication Dynamic Management Views and Functions (Azure SQL Database)
sys.dm_geo_replication_link_status (Azure SQL Database) sys.dm_geo_replication_link_status (Azure SQL Database)
sys.geo_replication_links (Azure SQL Database) sys.geo_replication_links (Azure SQL Database)
ALTER DATABASE (Azure SQL Database)ALTER DATABASE (Azure SQL Database)