How to debug a trigger in ssms 20.2, sql 2019

Sushil Agarwal 406 Reputation points
2024-09-03T18:09:39.9366667+00:00

How to debug a sql 2019 table tigger in ssms, i am nit seeing debug in ssms

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
13,998 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Olaf Helper 45,106 Reputation points
    2024-09-03T18:20:55.99+00:00

    As far as I known you can not debug trigger code, because a trigger is executed event driven (DML), not as a directly part of you code execution.

    0 comments No comments

  2. Erland Sommarskog 112.7K Reputation points MVP
    2024-09-03T21:11:59.26+00:00

    You debug it with PRINT and SELECT statements.

    Older versions of SSMS had a debugger, but there were lots of issues, particularly if you wanted to debug on a remote instance. Myself, I gave up using a debugger for SQL Server twenty years ago. Too much hassle to get it working. And the returns were diminishing, since you could not inspect tables.

    0 comments No comments

  3. LiHongMSFT-4306 28,041 Reputation points
    2024-09-04T02:24:50.2766667+00:00

    Hi @Sushil Agarwal

    There is direct way to debug triggers in SSMS. You could use print statements or temporary tables to check results.

    Also, you could use SQL Server Data Tools (SSDT) to debug particular database objects, such as stored procedures and triggers.

    See this doc: How to: Debug Database Objects.

    Best regards,

    Cosmog


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.