Select “where clause” evaluation order

前端 未结 7 1583
梦毁少年i
梦毁少年i 2020-12-06 09:40

In Sql Server 2005 when I have multiple parameters do I have the guarantee that the evaluation order will always be from left to right?

Using an exa

7条回答
  •  借酒劲吻你
    2020-12-06 09:44

    The MS SQL Server query optimizer does short circuit, yes. Guaranteed.

    Run this:

    select 1 where 1 = 0 and 1 / 0 = 10
    

    It will run just fine and not error even though you're dividing by zero because the query optimizer will short-circuit evaluate the where clause. This has implications for any where clause where you're "and"-ing and one of the and parts is a constant.

提交回复
热议问题