问题
I'm stepping through a stored procedure in SQL Server Management Studio 2008 (SSMS). The code creates some table variables as well as temporary # tables that I would like to inspect as I go along. Now the other local variables I can see in the "Locals" window and while the table variables are listed there, I can't see their contents. I would also like to inspect the # temp tables but again any select statement that I want to run against them will need to come from the same session as the code that I'm stepping through.
Is this possible in the SSMS 2008 debugger?
回答1:
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.
回答2:
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
回答3:
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.
来源:https://stackoverflow.com/questions/4408724/how-do-i-inspect-table-variables-and-temporary-tables-from-within-a-debugging-se