<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://sqlblog.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Search results matching tags 'Automation', 'DBA', and 'Developer'</title><link>http://sqlblog.com/search/SearchResults.aspx?o=DateDescending&amp;tag=Automation,DBA,Developer&amp;orTags=0</link><description>Search results matching tags 'Automation', 'DBA', and 'Developer'</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP2 (Build: 61129.1)</generator><item><title>Everybody Needs a Test Harness</title><link>http://sqlblog.com/blogs/kevin_kline/archive/2011/10/31/everybody-needs-a-test-harness.aspx</link><pubDate>Mon, 31 Oct 2011 14:17:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:39489</guid><dc:creator>KKline</dc:creator><description>&lt;p&gt;When you're developing new Transact-SQL code or modifying some existing code, do you just launch directly into programming?&lt;/p&gt;&lt;p&gt;I know that I did just that, for years.  It wasn't until I was trying to performance tune some existing code that I realized I hadn't actually taken caching of data and execution plans into account.  So all those modified stored procedures that I was so proud of might not actually be faster than the first generation of procedures because I hadn't checked to ensure that I was testing cached programs against uncached programs (and, by extension, the data used by those programs).  That's easy enough to fix with a &lt;em&gt;test harness.&lt;/em&gt;  Test harness were originally an actual, physical harness used by engineers to clamp down parts of an electrical or mechanical device they were prototyping.  Ours is no different.  It locks down all of the assumptions about our code (like my early, false assumption that I didn't need to clear the caches) and adds a metric or two for good measure - literally - so we can better measure what's happening in that code.&lt;/p&gt;&lt;p&gt;Here's what my test harness looks like: &lt;/p&gt;&lt;pre style="padding-left:30px;"&gt;/* Transact-SQL test harness by Kevin Kline, http://KevinEKline.com, Twitter at kekline */ &lt;/pre&gt;&lt;pre style="padding-left:30px;"&gt;/* Flush dirty pages from the buffer to the database files. */&lt;/pre&gt; &lt;pre style="padding-left:30px;"&gt;CHECKPOINT;&lt;/pre&gt; &lt;pre style="padding-left:30px;"&gt;/* Flush the data cache and procedure cache, respectively. For DEV environments only! */&lt;/pre&gt; &lt;pre style="padding-left:30px;"&gt;DBCC DROPCLEANBUFFERS; &lt;/pre&gt;&lt;pre style="padding-left:30px;"&gt;DBCC FREEPROCCACHE;&lt;/pre&gt; &lt;pre style="padding-left:30px;"&gt;/* Enable statistics tracking for IO and timings. Remember, SET commands remain enabled during a session until disabled. */&lt;/pre&gt; &lt;pre style="padding-left:30px;"&gt;SET STATISTICS IO ON; &lt;/pre&gt;&lt;pre style="padding-left:30px;"&gt;SET STATISTICS TIME ON;&lt;/pre&gt; &lt;pre style="padding-left:30px;"&gt;-- Whatever SQL code you'd like to process goes below.&lt;/pre&gt;&lt;pre style="padding-left:30px;"&gt;SELECT SalesOrderID&lt;/pre&gt;&lt;pre style="padding-left:30px;"&gt;FROM Sales.SalesOrderHeader H&lt;/pre&gt;&lt;pre style="padding-left:30px;"&gt;WHERE CustomerID = 344&lt;/pre&gt;&lt;pre style="padding-left:30px;"&gt;GO&lt;/pre&gt; &lt;pre style="padding-left:30px;"&gt;SET STATISTICS IO OFF; &lt;/pre&gt;&lt;pre style="padding-left:30px;"&gt;SET STATISTICS TIME OFF;&lt;/pre&gt; &lt;pre style="padding-left:30px;"&gt;/* Textual Execution Plans, if desired. &lt;/pre&gt;&lt;pre style="padding-left:30px;"&gt;SET SHOWPLAN_TEXT ON; &lt;/pre&gt;&lt;pre style="padding-left:30px;"&gt;SET SHOWPLAN_TEXT OFF; &lt;/pre&gt;&lt;pre style="padding-left:30px;"&gt;*/&lt;/pre&gt;&lt;p&gt; I also like to include the execution plans a lot of the time.  You might wonder why I don't save the execution plans for the GUI in SSMS?  Well, I'm a big advocate of scripting in general because I like to automate activities.  By pulling the execution plans using scripts, I can use SQLCMD to schedule a large number of query executions during the evening and have the results ready for analysis when I come back into the office in the morning.  &lt;em&gt;Workin' smarter, not harder, Baby!&lt;/em&gt;&lt;/p&gt;&lt;p&gt;So how does this test harness work for you?  Do you use other elements in yours?  If so, share your experiences here!&lt;/p&gt;&lt;p&gt;Thanks,&lt;/p&gt;&lt;p&gt;-Kevin&lt;/p&gt;&lt;p&gt;-&lt;a title="C'mon. You know you want to." href="http://twitter.com/kekline" target="_blank"&gt;Follow me on Twitter&lt;/a&gt;&lt;/p&gt;</description></item></channel></rss>