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

适用对象:yesSQL Server(从 2008 版开始)noAzure SQL 数据库noAzure SQL 数据仓库no并行数据仓库APPLIES TO: yesSQL Server (starting with 2008) noAzure SQL Database noAzure 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 = ON1 = 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). 跟踪标志号的列标题为 Global Trace Flag 或 Session Trace Flag,具体取决于要检查全局跟踪标志还是会话跟踪标志的状态。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 ServerSQL Server 中,有两种跟踪标志:会话和全局。In SQL ServerSQL 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

要求 公共 角色具有成员身份。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)