Language to Avoid in Queries

Use of inequality operators in SQL queries forces databases to use table scans to evaluate the inequalities. These queries generate high I/O if they run regularly against large tables.

For example, using any WHERE expression with NOT in it:

WHERE column_name != some_value

WHERE column_name <> some_value

If you must run these queries, restructure the queries to eliminate the NOT keyword or operator, for example:

SELECT * FROM tableA WHERE col1 < 'value' or col1 > 'value'

  

Instead of:

SELECT * FROM tableA WHERE col1 != 'value'

  

SQL Server can use the index (preferably clustered), if it is built on col1, rather than resorting to a table scan.