如何在 MS SQL Management Studio 2012 中的调试会话期间查看表变量中的数据? [英] How to view data in table variables during debugging session in MS SQL Management Studio 2012?

查看:18
本文介绍了如何在 MS SQL Management Studio 2012 中的调试会话期间查看表变量中的数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 SSMS 2012 调试复杂的 T-SQL 脚本.

I would like to debug a complex T-SQL script using SSMS 2012.

我可以在调试模式下运行脚本并设置断点,以及单步执行脚本,但我看不到存储在表变量中的值.

I can run the script in debug mode and place breakpoints, as well as step through my script, but I can't see the values stored in my table variables.

Locals 窗口中,我看到所有这些变量,但它们的值显示为 (table):

In the Locals window I see all these variables, but their value is shown as (table):

无法通过上下文菜单或单击变量来查看变量的内容.

There is no way to view the content of the variable through the context menu or by clicking on the variable.

我尝试使用 Immediate Window 对表变量运行查询,但这似乎也不起作用.

I tried to use the Immediate Window to run a query on the table variable, but this seems not to work either.

知道如何在调试会话中从表变量中获取值吗?

Any idea how I can get the values from my table variables in the debug session?

推荐答案

虽然我在任何地方都找不到任何明确指出您不能检查表变量的文档,但我认为这是不可能的.来自 Transact-SQL 调试器

Whilst I can't find any documetation, anywhere, that explicitly states that you cannot inspect table variables, I don't believe that it's possible. From Transact-SQL Debugger

当地人观看.这些窗口显示当前分配的 Transact-SQL 表达式.表达式是计算结果为单个标量表达式的 Transact-SQL 子句.Transact-SQL 调试器支持查看引用 Transact-SQL 变量、参数或名称以 @@ 开头的内置函数的表达式.这些窗口还显示当前分配给表达式的数据值.

Locals and Watch. These windows display currently allocated Transact-SQL expressions. Expressions are Transact-SQL clauses that evaluate to a single, scalar expression. The Transact-SQL debugger supports viewing expressions that reference Transact-SQL variables, parameters, or the built-in functions that have names that start with @@. These windows also display the data values that are currently assigned to the expressions.

(我的重点)

也就是说,您只能检查标量.

That is, you can only inspect scalars.

关于您尝试使用立即窗口,调试器命令和功能的限制 说:

As to your attempt to use the Immediate window, the Limitations on Debugger Command and Features says:

显示立即窗口,但您不能用它做任何有用的事情,例如将变量设置为值或查询数据库.

The Immediate window is displayed, but you cannot do anything useful with it, such as setting a variable to a value, or querying the database.

<小时>

我从来没有真正使用过调试器 - 每次我查看它时,都会遇到这样的限制.


I've never really used the debugger much - everytime I've looked into it, I encounter limitations like this.

这就是为什么我仍然倾向于使用old-skool"/printf"方法来调试 SQL - 在整个代码中大量包含额外的 SELECT * 显示表的当前状态,以及额外的 PRINTRAISERROR 显示其他状态的消息,等等.然后正常运行代码,直到你把它敲定.

That's why I still tend to use "old-skool"/"printf" approaches to debug SQL - include extra SELECT *s liberally throughout the code showing the current state of tables, and extra PRINT or RAISERROR messages that show other states, etc. And then just run the code normally, until you've bashed it into shape.

这篇关于如何在 MS SQL Management Studio 2012 中的调试会话期间查看表变量中的数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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