OR Operator Short-circuit in SQL Server

后端 未结 3 1625
南笙
南笙 2020-11-27 22:22

I want to consult SQL Server OR short-circuit

Code:

   DECLARE @tempTable table
      (
         id int
      )
      INSERT @tempTable(id) values(1         


        
3条回答
  •  难免孤独
    2020-11-27 22:57

    Just stumbled over this question, and had already found this blog-entry: http://rusanu.com/2009/09/13/on-sql-server-boolean-operator-short-circuit/

    The SQL server is free to optimize a query anywhere it sees fit, so in the example given in the blog post, you cannot rely on short-circuiting.

    However, a CASE is apparently documented to evaluate in the written order - check the comments of that blog post.

提交回复
热议问题