How to debug a T-SQL trigger?

You’re actually over-thinking this.

I first run this query in one window (to set things up):

create table X(ID int not null)
create table Y(ID int not null)
go
create trigger T_X on X
after insert
as
    insert into Y(ID) select inserted.ID
go

I can then discard that window. I open a new query window, write:

insert into X(ID) values (1),(2)

And set a breakpoint on that line. I then start the debugger (Debug from menu or toolbar or Alt-F5) and wait (for a while, the debugger’s never been too quick) for it to hit that breakpoint. And then, having hit there, I choose to Step Into (F11). And lo (after another little wait) a new window is opened which is my trigger, and the next line of code where the debugger stops is the insert into Y... line in the trigger. I can now set any further breakpoints I want to within the trigger.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)