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

后端 未结 7 1464
温柔的废话
温柔的废话 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:08

    I saw Date's colleague Hugh Darwen discuss this issue in an excellent presentation "How To Handle Missing Information Without Using NULL", which is available on the Third Manifesto website.

    His solution is a variant on your second approach. It's sixth normal form, with tables to hold both Date of Birth and identifiers where it is unknown:

    #  +-----------------------------+ 1    0..1 +----------------------------+
    #  |         People'             | <-------> |         DatesOfBirth       |
    #  +------------+----------------+           +------------+---------------+
    #  |  PersonID  |  Name          |           |  PersonID  |  DateOfBirth  |
    #  +============+----------------+           +============+---------------+
    #  |  1         |  Banana Man    |           ! 2          | 20-MAY-1991   |
    #  |  2         |  Satsuma Girl  |           +------------+---------------+
    #  +------------+----------------+
    #                                  1    0..1 +------------+
    #                                  <-------> | DobUnknown |
    #                                            +------------+
    #                                            |  PersonID  |
    #                                            +============+
    #                                            | 1          |
    #                                            +------------+
    

    Selecting from People then requires joining all three tables, including boilerplate to indicate the unknown Dates Of Birth.

    Of course, this is somewhat theoretical. The state of SQL these days is still not sufficiently advanced to handle all this. Hugh's presentation covers these shortcomings. One thing he mentions is not entirely correct: some flavours of SQL do support multiple assignment - for instance Oracle's INSERT ALL syntax.

提交回复
热议问题