Why doesn't SQL support “= null” instead of “is null”?

前端 未结 12 2044
不知归路
不知归路 2020-11-29 11:11

I\'m not asking if it does. I know that it doesn\'t.

I\'m curious as to the reason. I\'ve read support docs such as as this one on Working With Nu

12条回答
  •  渐次进展
    2020-11-29 11:31

    The reason why it's off by default is that null is really not equal to null in a business sense. For example, if you were joining orders and customers:

    select * from orders o join customers c on c.name = o.customer_name
    

    It wouldn't make a lot of sense to match orders with an unknown customer with customers with an unknown name.

    Most databases allow you to customize this behaviour. For example, in SQL Server:

    set ansi_nulls on
    if null = null  
        print 'this will not print' 
    set ansi_nulls off
    if null = null  
        print 'this should print'
    

提交回复
热议问题