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

前端 未结 8 2004
予麋鹿
予麋鹿 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:23

    Do not allow a column to be defined as NULL if at all possible. For me it does not have anything to do with the business rule of what you want NULL to mean it has to do with disk I\O.

    In SQL Server a nullable column, say a character 10, will take one bit in a bitmap when null and 10 bytes when not nullable. So how does having a null hurt disk I/O. The way it hurts is when a value is inserted into a column where a null used to be. Since SQL did not reserve space there is not room in the row to just put the value so SQL Server has to shift data around to make room. Page splits, fragmentation, updating the RID if this is a HEAP, etc all hurt disk I/O.

    BTW if there is a gender table we could add another row for "Unable to determine the true sexual origin or state of the individual".

提交回复
热议问题