Let us say that you are creating a system to store characteristics of different countries. There will be same basic columns like name, population, capital city etc. But let us say in addition to it you want to store some country specific information like highest mountain, nearest ocean, most famous food etc. These columns will be different for each country.
How can this be done using a relational database like MySQL. I know this is easier using a schema-less NoSQL database like MongoDB where each country can be stored as a separate document. But can something like this be done using relational DBs?
With only text fields you need two additional tables:
Alternatively, if there are only a couple of properties, simply store NULL for unknown values.
It can. As I learned today by asking another question on SO, this is called EAV (for Entity-Attribute-Value model). I found an interesting explanation about it on wikipedia.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With