且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在 MS SQL Management Studio 2012 中的调试会话期间查看表变量中的数据?

更新时间:2023-02-06 18:32:40

虽然我在任何地方都找不到任何明确指出您不能检查表变量的文档,但我认为这是不可能的.来自 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.