Is it a normal practice when there're 2 columns and if one is true the other must false, and vise versa?

All we need is an easy explanation of the problem, so here it is.

I have something similar to this, but not precisely it:

I sell only coffee and tea, and for the next 50 years I’ll be selling only these. In a table "drinks" I have 2 columns: is_coffee? and is_tea?. Only one of these can be true, obviously, and if one is true, the other must be false.

Also, I have some columns that are specific to only coffee, when is_coffee? is true, and others to only tea.

Does it make sense hold all of them in a single table? Is it a normal situatation when there’re 2 columns and if one is true the other must false, and vise versa?

How to solve :

I know you bored from this bug, So we are here to help you! Take a deep breath and look at the explanation of your problem. We have many solutions to this problem, But we recommend you to use the first method because it is tested & true method that will 100% work for you.

Method 1

This is called transitive functional dependency and should be avoided to have a 3th normal form design.

To solve it you should move it to the type of product to another table.

And then you can have another table linked with specific attributes of coffee entity and another one with specific attributes of the tea entity.

Don’t be scared of the number of the tables, be scared of the consequences of not be in normal form.
(i.e. lack of performance, space, scalability)

Note: Use and implement method 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply