Database design: objects with different attributes

前端 未结 3 985
故里飘歌
故里飘歌 2020-12-19 07:59

I\'m designing a product database where products can have very different attributes depending on their type, but attributes are fixed for each type and types are not managea

3条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-19 08:39

    This actually a standard way to "enforce" a sort of OO design in a classical RDBMS.

    All the "common" attributes go on the master table (e.g. Price, if it is mantained at the product table level, could easily be part of the main table) while the specifics go on a subtable.

    In theory if you have sub-sub-types (e.g. magazines could be subtyped in daily newspapers and 4-colours periodicals, maybe, with periodicals having a date interval for shelf-life) you could add one or more sublevels too...

    This is pretty common (and proven) design. The only concern is that the master table will always be joined with at least a subtable for most operations. If you have zillions of items this could have performance implications.

    On the other hand, common operation like deleting an item (I'd suggest a logical deletion, setting a flag to "true" on the master table) would be done once for every kind of subtype.

    Anyway, go for it. And maybe google around for "Object oriented to RDBMS mappings" or somesuch for a complete discussion.

提交回复
热议问题