Database Design - Conditional Null Values

拥有回忆 提交于 2020-01-06 01:54:15

问题


I have a work_orders entity, it can have child work orders, so there is a parent_id on the table. There are cases where the child order can be invoiced separately or with the parent. So I have another column called bill_with_parent.

Since that bill_with_parent column only ever applies to child work orders, I've been setting it to NULL for non child work orders, and if it's a child, it's either going to be 0 or 1.

Is that the proper way to handle something like this?


回答1:


While it's not necessarily 'wrong'. I'd get rid of the null and just allow 0 and 1. Of course for parents it's always going to be 0, only a child could have both 1 or 0.

When you allow a field to be null you forever have to add protection for the null case in all your queries, so I'd reserve using null for use only with foreign fields keys or places where there literally no valid value.



来源:https://stackoverflow.com/questions/35467964/database-design-conditional-null-values

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!