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

前端 未结 7 2231
执念已碎
执念已碎 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条回答
  •  独厮守ぢ
    2020-11-27 14:07

    If @Region is not a null value (lets say @Region = 'South') it will not return rows where the Region field is null, regardless of the value of ANSI_NULLS.

    ANSI_NULLS will only make a difference when the value of @Region is null, i.e. when your first query essentially becomes the second one.

    In that case, ANSI_NULLS ON will not return any rows (because null = null will yield an unknown boolean value (a.k.a. null)) and ANSI_NULLS OFF will return any rows where the Region field is null (because null = null will yield true)

提交回复
热议问题