Is the SQL WHERE clause short-circuit evaluated?

前端 未结 14 2468
时光取名叫无心
时光取名叫无心 2020-11-22 04:31

Are boolean expressions in SQL WHERE clauses short-circuit evaluated ?

For example:

SELECT * 
FROM Table t 
WHERE @key IS NULL OR (@key IS NOT NULL          


        
14条回答
  •  既然无缘
    2020-11-22 04:48

    This takes an extra 4 seconds in query analyzer, so from what I can see IF is not even shorted...

    SET @ADate = NULL
    
    IF (@ADate IS NOT NULL)
    BEGIN
        INSERT INTO #ABla VALUES (1)
            (SELECT bla from a huge view)
    END
    

    It would be nice to have a guaranteed way!

提交回复
热议问题