DBCC TRACESTATUS (Transact-SQL)DBCC TRACESTATUS (Transact-SQL)

本主題適用於:是SQL Server (從 2008 開始)否Azure SQL Database否Azure SQL 資料倉儲 否平行處理資料倉儲 THIS TOPIC APPLIES TO:yesSQL Server (starting with 2008)noAzure SQL DatabasenoAzure SQL Data Warehouse noParallel Data Warehouse

顯示追蹤旗標的狀態。Displays the status of trace flags.

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

語法Syntax

DBCC TRACESTATUS ( [ [ trace# [ ,...n ] ] [ , ] [ -1 ] ] )   
[ WITH NO_INFOMSGS ]  

引數Arguments

trace#trace#
這是會顯示狀態的追蹤旗標編號。Is the number of the trace flag for which the status is displayed. 如果是 trace#,而且沒有指定 -1,則工作階段所啟用的所有追蹤旗標,都會全部顯示出來。If trace#, and -1 are not specified, all trace flags that are enabled for the session are displayed.

nn
這是一個預留位置,表示可以指定多個追蹤旗標。Is a placeholder that indicates multiple trace flags can be specified.

-1-1
顯示全域啟用的追蹤旗標狀態。Displays the status of trace flags that are enabled globally. 如果指定 -1,但沒有 trace#,則所有啟用的全域追蹤旗標都會顯示出來。If -1 is specified without trace#, all the global trace flags that are enabled are displayed.

WITH NO_INFOMSGSWITH NO_INFOMSGS
抑制所有嚴重性層級在 0 到 10 的參考用訊息。Suppresses all informational messages that have severity levels from 0 through 10.

結果集Result Sets

下表描述結果集中的資訊。The following table describes the information in the result set.

資料行名稱Column name 描述Description
TraceFlagTraceFlag 追蹤旗標的名稱Name of trace flag
狀態Status 指出追蹤旗標是設為 ON 還是 OFF (無論是全域或工作階段)。Indicates whether the trace flag is set ON of OFF, either globally or for the session.

1 = ON 1 = ON

0 = OFF0 = OFF
全域Global 指出追蹤旗標是否為全域設定Indicates whether the trace flag is set globally

1 = True1 = True

0 = False0 = False
工作階段Session 指出追蹤旗標是否針對工作階段而設定Indicates whether the trace flag is set for the session

1 = True1 = True

0 = False0 = False

DBCC TRACESTATUS 會傳回一個資料行代表追蹤旗標編號,以及一個資料行代表狀態。DBCC TRACESTATUS returns a column for the trace flag number and a column for the status. 其目的是指出追蹤旗標是 ON (1) 還是 OFF (0)。This indicates whether the trace flag is ON (1) or OFF (0). 追蹤旗標編號的資料行標題是全域追蹤旗標工作階段追蹤旗標,這會隨著您所檢查的是全域追蹤旗標狀態還是工作階段追蹤旗標狀態而不同。The column heading for the trace flag number is either Global Trace Flag or Session Trace Flag, depending on whether you are checking the status for a global or a session trace flag.

RemarksRemarks

[SQL Server]SQL Server 中有兩種類型的追蹤旗標:工作階段和全域。In [SQL Server]SQL Server, there are two types of trace flags: session and global. 工作階段追蹤旗標用於某個連接,而且只會在該連接顯示出來。Session trace flags are active for a connection and are visible only for that connection. 全域追蹤旗標是設在伺服器層級,只要是該伺服器上的連接,都看得到它們。Global trace flags are set at the server level and are visible to every connection on the server.

PermissionsPermissions

需要 public 角色的成員資格。Requires membership in the public role.

範例Examples

下列範例會顯示目前全域啟用之所有追蹤旗標的狀態。The following example displays the status of all trace flags that are currently enabled globally.

DBCC TRACESTATUS(-1);  
GO  

下列範例會顯示追蹤旗標 25283205 的狀態。The following example displays the status of trace flags 2528 and 3205.

DBCC TRACESTATUS (2528, 3205);  
GO  

下列範例會顯示追蹤旗標 3205 是否全域啟用。The following example displays whether trace flag 3205 is enabled globally.

DBCC TRACESTATUS (3205, -1);  
GO  

下列範例會列出所有針對目前工作階段而啟用的追蹤旗標。The following example lists all the trace flags that are enabled for the current session.

DBCC TRACESTATUS();  
GO  

另請參閱See Also

DBCC (Transact-SQL)DBCC (Transact-SQL)
DBCC TRACEOFF (Transact-SQL)DBCC TRACEOFF (Transact-SQL)
DBCC TRACEON (Transact-SQL)DBCC TRACEON (Transact-SQL)
追蹤旗標 (Transact-SQL)Trace Flags (Transact-SQL)