Identifying Search Arguments

A SARG is defined as a WHERE clause that compares a column to a constant. The format of a SARG is as follows:

Column operator constant_expression [and...]

SARGs provide a way for the Query Optimizer to limit the rows searched to satisfy a query. The general goal is to match a SARG with an index to avoid a table scan. Valid operators for a SARG are =, >, <, >=, and <=, BETWEEN, and LIKE. Multiple SARGs can be combined with the AND clause. (A single index might match some or all of the SARGs ANDed together.) Following are examples of SARGs:

flag = 7

salary > 100000

city = 'Saratoga' and state = 'NY'

price between $10 and $20 (the same as price > = $10 and price <= $20)

100 between lo_val and hi_val (the same ...

Get Microsoft® SQL Server 2008 R2 Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.