sp_showplan <spid>, <batch_id> output,
<context_id> output,
<stmt_num> output,
<display_level>
要在未指定 batch_id、context_id 或 stmt_num 的情况下显示当前 SQL 语句的 showplan 输出:
sp_showplan <spid>, null, null, null
<spid>
是任何用户连接的进程 ID。使用 sp_who 可查看 spid。
<batch_id>
是唯一的非负批处理编号
<context_id>
是批处理中执行的每个过程(或触发器)的唯一编号。
<stmt_num>
是批处理中当前语句的编号。<stmt_num> 必须为正数。
<display_level>
确定 sp_showplan 显示运算符树和资源统计信息的方式。下列各项之一:
如果没有为 <display_level> 提供值,sp_showplan 则显示最低输出级别。
显示 <batch_id>、<context_id> 和 <statement_id> 参数的值。在对 <spid> 为 99 的用户会话执行的后续 sp_showplan 迭代中,可以使用这些值来检索查询计划:
declare @batch int
declare @context int
declare @statement int
exec sp_showplan 99, @batch output, @context output, @statement output
显示使用 <spid> 参数的用户会话中当前运行的语句的 showplan 输出。这些值可用于检索值 99:
sp_showplan 99, null, null, null
显示 spid 数为 62 的运算符树和资源统计信息:
sp_showplan 62, null, null, null, 'long'
使用 sp_showplan 时,还存在一些其它注意事项:
SAP ASE Monitor™ Server 运行。
<context_id> 大于 0,则当前语句嵌入在从原 SQL 批处理调用的存储过程(或触发器)中。选择具有相同 <spid> 值的 sysprocesses 行可以显示过程 ID 和语句 ID。