Getting debug output in SQL Server Management Studio

You can simply use PRINT in the pleces that you suspect can cause problems

e.g.

print 'Step 1'
insert into tableA -- some code here
...
print 'Step 2'
etc

You can also wrap your code into block of TRY CATCH statements and throw custom errors or print error messages if something goes wrong


PRINT statements as suggested by @kristof would do what you want.

However you could run SQL Profiler side-by-side when you execute the script, catching all classes in the Errors and Warnings section and all SQL:StmtStarting events -- this would mean you wouldn't have to edit your script.

Tags:

Sql

Sql Server