Options for eliminating NULLable columns from a DB model (in order to avoid SQL's three-valued logic)?

后端 未结 7 1473
温柔的废话
温柔的废话 2021-02-08 20:19

Some while ago, I\'ve been reading through the book SQL and Relational Theory by C. J. Date. The author is well-known for criticising SQL\'s three-valued logic (3VL).

7条回答
  •  南笙
    南笙 (楼主)
    2021-02-08 21:01

    One option is to use explicit option types, analogous to Haskell's Maybe functor.

    Unfortunately a lot of existing SQL implementations have poor support for user-defined algebraic data types and even poorer support for user-defined type constructors that you really need to do this cleanly.

    This recovers a sort of "null" for only those attributes where you explicitly ask for it, but without null's silly three-valued logic. Nothing == Nothing is True, not unknown or null.

    Support for user-defined algebraic types also helps when there are a few reasons for missing information, for example a database equivalent of the following Haskell type would be a good solution for the obvious application:

    data EmploymentStatus = Employed EmployerID | Unemployed | Unknown
    

    (Of course, a database supporting this would also need to support the more-complicated-than-usual foreign key constraint that comes with it.)

    Short of this, I agree with APC's and onedaywhen's answers about 6NF.

提交回复
热议问题