I am stuck between choosing a way of database table designing. The scenario is that I need to make database of cellphones and tablets specifications. The database can be in two ways...
1- Long columns way, in which I will add each specification field as an individual column which will result in 38 columns, resulting in a complete product specification in just a single row.
2- Long rows way, in which I will ad just 5 columns: id, name, value, brand, and model, saving each product specification in a name value pair which will result in 38 rows for each specification.
Which way should I go.. and why..?
The first solution is the more traditional. The second is called "entity-attribute-value" (EAV).
For most applications, the first is preferable. For instance, in the second method, all values would have to be the same type. But one might be the date the product was released, and others might be strings.
The second also results in much clearer queries. Having to bring together the attributes from dozens of rows to describe a singel model can be inefficient. At the very least, it results in more cumbersome queries.
Such a data structure also makes it more difficult to do data validation checks and to have foreign key relationships to other tables.
Finally, the EAV approach uses more space.
There are some cases where EAV is quite valuable. For instance, if you have thousands of attributes and only a few are being used for any given product. 38 columns, though, is quite reasonable for a single table.
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