I need to understand and clarify some T-SQL stored procedures that contain important business logic. Does anyone know of any tools, tips, tricks, or hints that can be used for unit testing so I can refactor this sql without breaking it?
Simon Harriyott suggests using TSqlUnit for this. There is more information about his process on his blog.
why do you need to refactor?
Add a bunch of PRINT statements and manually run it from the Management Studio. If you print the proper info, you should be able to trace through the code and understand what is going on.
If you don't know what parameters to use, modify it to send the input parameters to a log file, then use those to run it manually.
If you have access to Visual Studio Team System Database Edition, then it comes with a bunch of unit-testing tools geared specifically for databases, as explained in this MSDN article.
I use C# for unit testing stored procedures - that is way more efficient than T-SQL. The first link explains how to quickly generate unit tests.
For help on refactoring itself (as opposed to getting it under test so you can refector), do not forget to check out Refactoring Databases (either the book or the website).
I did write tests for stored procedures with the calling code (in my case Java with dbunit), but I do not know how it would compare against other methods.