How do I inspect table variables and temporary tables from within a debugging session in SSMS 2008?

给你一囗甜甜゛ 提交于 2019-12-06 09:12:56

I built a procedure which will display the content of a temp table from another database connection. (which is not possible with normal queries). Note that it uses DBCC PAGE & the default trace to access the data so only use it for debugging purposes.

snth

This is largely the same question as this one: How to see the values of a table variable at debug time?

It appears that the short answer is: NO! This hasn't been implemented in SSMS 2008.

See this post on Microsoft Connect: SQL Debugging - All About Tables: Table Variables, #Temp, ##Global Temp, Source (Input) and Output Tables

What I do in a complex proc is add an input varaiable with a default value of 0 to the end of whatever variables I have called @test. (by doing it this way, I won't break any exisiting calls to the proc)

Then at each point where I might want to see the values of a table variable or temp table I put an if statement and I might even add a column so I know at what point I am looking at the table:

IF @test = 1 BEGIN SELECT 'after updating field 3' as TestStep, * FROM #temp END

Now they only run if running in test mode and I can see whatever I need to when debugging a problem two years from now. I also print any dynamic SQl statments I created in the test mode as well.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!