I’m always at a loss of how best to represent a small number of items with a large number of properties in an SQL database. Tables feel great when the number of rows is dramatically larger than the number of columns. But when it’s the other way around, when you have one or two rows in a table with 30 columns, it feels strange. As if it’s out of balance.

I do wonder if some of these alternatives could work better:

  • Having one DB table contain the items and another containing the item properties. This second table will only have four columns: id, item_id, property, and value.
  • Storing the properties in a JSON column or similar.

These will probably work well for items with dynamic properties, or when only a subset have values at any one time. It would also be viable if one wouldn’t need to select on these properties, as querying this information would be a pain (although doable). Would it also work if the items don’t have dynamic properties? It’ll probably reduce the number of migrations involved.

This is probably just a me problem, and I should just write the table “naturally,” with one column per property. It’s not like the database cares.