ANSI_NULLS and QUOTED_IDENTIFIER killed things. What are they for?

后端 未结 4 572
北海茫月
北海茫月 2020-12-24 02:43

NOTE: I checked Understanding QUOTED_IDENTIFIER and it does not answer my question.

I got my DBAs to run an index I made on my Prod servers (they looked it over and

4条回答
  •  攒了一身酷
    2020-12-24 03:00

    ANSI_NULLS ON makes any binary boolean expression with a null value evaluate to false. Using the following template:

    declare @varA, @varB int
    
    if 
    begin
        print 'true'
    end
    else
    begin
        print 'false'
    end
    
    
    @varA: NULL; @varB: NULL; @varA = @varB evaluates to false
    @varA: 1; @varB: NULL; @varA <> @varB evaluates to false
    

    The proper way to test for null is to use is [not] NULL

    @varA: NULL; @varA is NULL evaluates to true
    @varA: 1; @varA is not NULL evaluates to true
    

    QUOTED_IDENTIFER ON merely allows you to use double quotes to delimit identifiers (bad idea IMO, just user square brackets)

    from tblA "a" -- ok when ON, not ok when OFF
    from tblA [a] -- always ok
    

提交回复
热议问题