• Carlo Romagnano (8/24/2010)


    One way to avoid worrying about NULLs is never to use them, always declaring columns as not allowing NULLs and designating default values for "empty" or "unknown". This will save you keystrokes, especially when you want to check whether a column does not have a certain value. However, you will anyway probably have to write logic for when columns have the designated default values.

    TERRIBLE!

    VERY TERRIBLE!

    Agreed.

    How NULL behaves might cause some unexpected results, but far less from how such "magic values" behave.

    I'd say that, as long as you use NULLs as intended (i.e., to represent missing data without inferring anything about the reason it might be missing), how SQL Server treats the NULL values will in 99% of all cases match what humans would do when asked to operate on incomplete data. All without any special extra handling. Using "magic values" means you have to write special handling to mimic default NULL behaviour in those 99% of all cases.


    Hugo Kornelis, SQL Server/Data Platform MVP (2006-2016)
    Visit my SQL Server blog: https://sqlserverfast.com/blog/
    SQL Server Execution Plan Reference: https://sqlserverfast.com/epr/