In SQL Server, what does “SET ANSI_NULLS ON” mean?

前端 未结 7 2263
执念已碎
执念已碎 2020-11-27 13:22

The definition says:

When SET ANSI_NULLS is ON, a SELECT statement that uses WHERE column_name = NULL returns zero rows even if there are null values

7条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-27 14:08

    Set ANSI NULLS OFF will make NULL = NULL comparision return true. EG :

            SET ANSI_NULLS OFF
            select * from sys.tables
            where principal_id = Null
    

    will return some result as displayed below: zcwInvoiceDeliveryType 744547 NULL zcExpenseRptStatusTrack 2099048 NULL ZCVendorPermissions 2840564 NULL ZCWOrgLevelClientFee 4322525 NULL

    While this query will not return any results:

            SET ANSI_NULLS ON 
            select * from sys.tables
            where principal_id = Null
    

提交回复
热议问题