Programming

T-SQL에서 디버그 시간에 테이블 변수의 값을 보는 방법은 무엇입니까?

procodes 2020. 5. 19. 20:31
반응형

T-SQL에서 디버그 시간에 테이블 변수의 값을 보는 방법은 무엇입니까?


디버그 시간 동안 SSMS (SQL Server Management Studio)의 테이블 값 변수에서 값 (행과 셀)을 볼 수 있습니까? 그렇다면 어떻게?

여기에 이미지 설명을 입력하십시오


이 Microsoft Connect 링크에 따라 아직 구현되지 않았습니다 : Microsoft Connect


DECLARE @v XML = (SELECT * FROM <tablename> FOR XML AUTO)

위의 내용을 테이블 내용을 보려는 지점에 삽입하십시오. 테이블의 내용은 로컬 창에서 XML로 렌더링되거나 @v시계 창에 추가 할 수 있습니다 .

여기에 이미지 설명을 입력하십시오


이 프로젝트 https://github.com/FilipDeVos/sp_select 에는 sp_select임시 테이블에서 선택할 수 있는 저장 프로 시저 가 있습니다.

용법:

exec sp_select 'tempDb..#myTempTable'

저장 프로 시저를 디버깅하는 동안 새 탭을 열고이 명령을 실행하여 임시 테이블의 내용을 볼 수 있습니다.


저장 프로 시저에서 전역 임시 테이블 ## temptable을 만들고 저장 프로 시저 내에 테이블의 데이터를이 임시 테이블에 삽입하는 삽입 쿼리를 작성하십시오.

이 작업이 완료되면 새 쿼리 창을 열어 임시 테이블의 내용을 확인할 수 있습니다. "select * from ## temptable"을 사용하십시오.


선택 쿼리를 사용하여 확인하려는 테이블을 다양하게 표시하십시오.

http://www.simple-talk.com/sql/learn-sql-server/management-studio-improvements-in-sql-server-2008/


플러그인이 없으면 이것이 불가능하다는 결론에 도달했습니다.


SQL Server Profiler 2014 lists the content of table value parameter. Might work in previous versions too. Enable SP:Starting or RPC:Completed event in Stored Procedures group and TextData column and when you click on entry in log you'll have the insert statements for table variable. You can then copy the text and run in Management Studio.

Sample output:

declare @p1 dbo.TableType
insert into @p1 values(N'A',N'B')
insert into @p1 values(N'C',N'D')

exec uspWhatever @PARAM=@p1

Why not just select the Table and view the variable that way?

SELECT * FROM @d

Sorry guys, I'm a little late to the party but for anyone that stumbles across this question at a later date, I've found the easiest way to do this in a stored procedure is to:

  1. Create a new query with any procedure parameters declared and initialised at the top.
  2. Paste in the body of your procedure.
  3. Add a good old fashioned select query immediately after your table variable is initialised with data.
  4. 프로 시저에서 3.이 마지막 명령문이 아닌 경우 동일한 행에 중단 점을 설정하고 디버깅을 시작한 후 중단 점으로 계속 진행하십시오.
  5. 이익!!

messi19의 대답은 받아 들일 수있는 IMHO이어야합니다. 왜냐하면 내 것보다 간단하고 대부분을하기 때문입니다.하지만 나와 같은 사람이고 검사하려는 루프 내부에 테이블 변수가 있으면이 작업을 훌륭하게 수행합니다. 너무 많은 노력이나 외부 SSMS 플러그인없이.

참고 URL : https://stackoverflow.com/questions/1900857/how-to-see-the-values-of-a-table-variable-at-debug-time-in-t-sql

반응형