Wednesday, 14 August 2013

SQL - What is Sargable?

Basically a query is Sargable if it can make use of indexes to improve performance.

What makes a query non-Sargable?
The most common way of making a query non-Sargable is by reference a field in a function in the where clause of a query.

For example:

SELECT ... FROM ...
WHERE Year(myDate) = 2008
This can be better written as:
WHERE myDate >= '01-01-2008' AND myDate < '01-01-2009'

So .. moral of the story ..
Avoid using functions that references a field inside the where clause of your query.

1 comment:

  1. I can't understand your post. What do you want to say? It creates the confusion. Please share more blogs and explains in details regarding sargable. Thanks.
    digital signature

    ReplyDelete