Why does NULL = NULL evaluate to false in SQL server

前端 未结 19 2002
一向
一向 2020-11-22 05:02

In SQL server if you have nullParam=NULL in a where clause, it always evaluates to false. This is counterintuitive and has caused me many errors. I do understa

19条回答
  •  离开以前
    2020-11-22 05:42

    To quote the Christmas analogy again:

    In SQL, NULL basically means "closed box" (unknown). So, the result of comparing two closed boxes will also be unknown (null).

    I understand, for a developer, this is counter-intuitive, because in programming languages, often NULL rather means "empty box" (known). And comparing two empty boxes will naturally yield true / equal.

    This is why JavaScript for example distinguishes between null and undefined.

提交回复
热议问题