I am creating an activity table with many types of activities. Let’s
say activities of type “jogging” will have elements a, b, and c while
activities of “football” will have elements a, d, and e. Can I create a
table in which the row elements for each column depend on that column’s
type? I have considered creating one table for each activity type or
creating a single table with rows for every activity’s options, but
there will be many activity types so it seems like a waste to use so
many tables or leave so many rows blank.
I am creating an activity table with many types of activities. Let’s say activities
Share
You cannot create such a table, it is not in the nature of databases to allow for “varargs”. That is the reason we have relations in databases to model this type of stuff.
For an evil quickhack you could store the variable number of arguments in one column in a specific format and parse this again. Something like “a:foo|e:bar|f:qux”. Don’t do this, it will get out of hand in about 1 day.
I second James’ proposal: redesign your tables. It should then look something like this.
Look up “normalization” (for example http://en.wikipedia.org/wiki/Database_normalization)