tags:

views:

28

answers:

2

If I have PRINT 'something' in a trigger, where does that output go?

I'm using SQL Server 2008R2

A: 

It depends on where you run the triggering statement. In Management Studio window, you will see the trigger output in the Messages tab.

bobs
What if it runs when no one is connect to SSMS? Suppose I have a trigger on a table that writes to another table when a record is inserted. A 3rd party program writes to the table. A print statement on that trigger goes where?
Andrew Vogel
+2  A: 

It print statement will bubble up to the query that initiated the trigger to execute. From which it will return to the client, SSMS, ADO, etc.

Dustin Laine
So if a third party initiates the request, they would need to have a mechanism to view that print. Thanks.
Andrew Vogel
However, if the triggering application is unattended, like say SSIS, what is the point of a print statment? I have never seen anyone use print in a trigger.
HLGEM
That's part of why I asked the question. It seems pointless most of the time to have that 'PRINT' then. (at least for me).
Andrew Vogel
In an unattended application you can use the `RAISEERROR` to trigger warnings and errors for you application to handle.
Dustin Laine
What if you don't have control of the application? Can you dump a trigger error somewhere else?
Andrew Vogel
Yes with the RAISEERROR, you can set it to log. Check out: http://msdn.microsoft.com/en-us/library/ms178592.aspx
Dustin Laine