How can I avoid NULLs in my database, while also representing missing data?

前端 未结 8 1998
予麋鹿
予麋鹿 2020-12-12 14:19

In SQL and Relational Theory (C.J. Date, 2009) chapter 4 advocates avoiding duplicate rows, and also to avoid NULL attributes in the data we store. While I have

8条回答
  •  青春惊慌失措
    2020-12-12 14:38

    I disagree with the author and would claim that NULL is actually the CORRECT way to handle missing data for optional fields. In fact, it's the reason that NULL exists at all...

    For your specific problem regarding gender:

    • Are you sure you want a gender table and incur the cost of an extra join for every query? For simple enumerated types it's not unreasonable to make the field an int and define 1=male, 2=female, NULL=unknown.

提交回复
热议问题