The problem: storing non-homogeneous data
In our database, we have a table called product
. We defined it such that it only contains very generic attributes, like the product's id
, name
, price
, the available quantity
, and a description
. But we will also need to store more specific attributes that depend on the product type: for example, for a shirt we will need to store the color and a size that is encoded as a character (S for small, M for medium, and so on); for a pair of shoes we will probably store the brand and the size, but in this case, the size is a number.
This is a typical problem we face every time we need to store heterogeneous data that could belong to the same logical class. Here, heterogeneous means that each entity has a variable number of specific attributes, and attributes with the same name could be of different types. How should we store heterogeneous data in a relational database?
There are several approaches to this problem. The optimal choice depends on the specific...