How to test a trigger?

Easy unit testing for databases in SQL Server Management Studio

How to test a trigger?

Postby AdamY » Thu Mar 28, 2013 8:19 pm

TableA has Trigger1 that inserts data into TableB. I'd like to test that the trigger works correctly. Can I do that with SQL Test? I haven't been able to find a way yet. Does FakeTable handle triggers?
Posts: 41
Joined: Fri Oct 15, 2010 7:24 pm

Postby stanori » Fri Mar 29, 2013 9:22 pm

Hi AdamY,

Thanks for your post. It looks like something simliar has been covered in stackoverflow: ... e-triggers

It looks like there is a workaround solution to make this happen.

Best Regards,
Steve Tanori
Product Support
Red Gate Software Ltd.
Posts: 84
Joined: Mon Apr 23, 2012 12:13 pm

Postby AdamY » Fri Oct 04, 2013 4:40 pm

kenbroz - the answer Steve (stanori) posted has a link to a work-around solution. tSQLt is working on a permanent solution, I think. The tSQLt Google Group is very helpful and has more info, too.
Posts: 41
Joined: Fri Oct 15, 2010 7:24 pm


Postby datacentricity » Mon Oct 07, 2013 2:22 pm

kenbroz wrote:why has been answered, I would like to know the answer because it has a similar problem.

The latest version of tSQLt (the framework that underpins RedGate's SQL Test) now has an ApplyTrigger method which used in conjunction with FakeTable should allow you to do test your trigger. Not sure of this version is packaged up with SQL test yet though.

I have successfully used SQL Test with a more recent build of tSQLt (based on the SQL script download via but YMMV.
\"Your mind is like a parachute, it works best when open\" Frank Zappa
\"Be wary of strong drink. It can make you shoot at tax collectors…and miss\" Robert Heinlein
twitter: @datacentricity
Posts: 28
Joined: Wed Jul 18, 2012 11:22 am
Location: London

Return to SQL Test

Who is online

Users browsing this forum: No registered users and 0 guests