Static Code Analysis and SARG-ability

This morning while coding a stored procedure for a SQL Server 2012 SSDT project in Visual Studio, I noticed an interesting little blue squiggly under one of the column references in the WHERE-clause of the statement I was working on.  Curiously, I hovered the mouse over it and was pleasantly surprised to see the following statement…

SR0006 : Microsoft.Rules.Data : A column in an expression to be compared in a predicate might cause a table scan and degrade performance.

Having read quite a few articles and discussions, like this one, by Rob Farley (blog | twitter) on the “SARG-ability” of statements, I’d like to think the concept is fairly well ingrained by now…but apparently not.  Thankfully Visual Studio was there with a friendly little reminder so that I could rewrite the statement before finishing up the stored proc and checking it it to TFS.

The complete list of the “Static Code Analysis” rules can be found under the SQL menu (Static Code Analysis –> Configure).  Here’s a screenshot for reference…

1 thought on “Static Code Analysis and SARG-ability

Leave a Reply