SQL Server: multiple sentences

Suppose I have a T-SQL command with several WHERE

conditions like this:

SELECT * 
FROM TableName
WHERE Column1 NOT LIKE '%exclude%'
  AND Column2 > 10

      

Will the query exclude the row as soon as it Column1

fails, or will it continue to check the next condition for Column2

?

I ask because I want to see if it would be more efficient to change my conditions to check if Column2 > 10

first before I get a more time consuming condition working.

Edit: if it matters, Column1

is of type bigint

and Column2

is of typentext

+3


source to share


2 answers


Sql will develop a query plan based on the available indexes and statistics. Sql does not necessarily have the expression "short-circuit" per se, because it is a procedural language, but ultimately the query plan will evaluate the short-circuit.



Expression substitution should not affect performance.

+2


source


As Mark said, replacing columns where the proposal will not change in performance. Instead, you can look for a change to NTEXT type in nvarchar (X), where x is the meaningful length of the data.



0


source







All Articles