sys.dm_exec_sql_text 如何工作? [英] How does sys.dm_exec_sql_text work?

查看:70
本文介绍了sys.dm_exec_sql_text 如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你能解释一下为什么吗

select * from sys.dm_exec_sql_text (sql_handle)抛出错误(无效的列名 'sql_handle'),但是

select * from sys.dm_exec_sql_text (sql_handle) throws an error (Invalid column name 'sql_handle'), but

select * from sys.sysprocesses cross apply sys.dm_exec_sql_text (sql_handle) 是一个有效的查询吗?谢谢.

select * from sys.sysprocesses cross apply sys.dm_exec_sql_text (sql_handle) is a valid query? Thank you.

推荐答案

您需要将其加入另一个表以获取 sql_handle(或 plan_handle).

You need to join it to another table to get the sql_handle (or plan_handle).

例如:

select a.session_id, a.start_time, status, a.command, text from sys.dm_exec_requests a cross apply sys.dm_exec_sql_text(sql_handle).

sys.dm_exec_sql_text 是一个表值函数,它需要将参数 sql_handleplan_handle 传递给它以返回一个结果与其他函数一样.返回的结果是一个表(而不是一个返回单个值的标量函数).

sys.dm_exec_sql_text is a table valued function, it expects the parameter sql_handle or plan_handle to be passed to it in order to return a result as other functions do. The result returned is a table (rather than a scalar function which would return a single value).

这篇关于sys.dm_exec_sql_text 如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆