title: Unit Tests in SQL Server Management Studio
body: <p>Is there a way to create simple unit tests for SQL queries in SSMS? I'm fairly new to T-SQL &amp; SSMS, but I'd like to try to carry some of my old TDD habits into this arena, if possible.</p>
  
  <p>So, for example, when I write the DDL to create complex functions and what-not, I'd like to have some way to include a unit test that (upon failure) would actually cause the output panel to display an error message upon execution. (This would be analagous to "breaking the build" in a normal programming environment.)</p>
  
  <p>Currently, when I write a function that is syntactically correct, then hit F5 to execute it, the output message is:</p>
  
  <pre><code>Command(s) completed successfully.
  </code></pre>
  
  <p>What I am looking for is some simple SQL trick to simulate basic red-light/green-light test cases. So I would write a series of test-statements that would pass only if my user-defined function is operating as intended. Otherwise an error message would be displayed, such as:</p>
  
  <pre><code>Msg 207, Level 16, State 1, Line 2
  Invalid statement.
  </code></pre>
  
  <p>which would allow me to jump immediately to the failing test and see what I did wrong.</p>
  
  <p>I don't expect there to be anything "built-in" for this, but is there some way I can "fake it"?</p>
  
  <p><strong>Update:</strong> I just learned you can <a href="http://msdn.microsoft.com/en-us/library/ee677615.aspx" rel="nofollow">throw exceptions</a> in SS2012, which I'm sure I could use for just this purpose, but unfortunately I'm stuck with SS2008 for now. Is there anything comparable in SS2008?</p>