问题
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