Designing SQL database to represent OO class hierarchy

In general I prefer obtion “B” (i.e. one table for base class and one table for each “concrete” subclass).

Of course this has a couple of drawbacks: first of all you have to join at least 2 tables whenever you have to read a full instance of a subclass. Also, the “base” table will be constantly accessed by anyone who has to operate on any kind of note.

But this is usually acceptable unless you have extreme cases (billions of rows, very quick response times required and so on).

There is a third possible option: map each subclass to a distinct table. This helps partitioning your objects but costs more in development effort, in general.

See this for a complete discussion.

(Regarding your “C” solution, using VARIANT: I can’t comment on the merits/demerits, because it looks like a proprietary solution – what is it ? Transact-SQL? and I am not familiar with it).

Leave a Comment