How important are lookup tables?

后端 未结 7 2010
你的背包
你的背包 2020-12-08 02:51

A lot of the applications I write make use of lookup tables, since that was just the way I was taught (normalization and such). The problem is that the queries I make are of

7条回答
  •  遥遥无期
    2020-12-08 03:27

    Question is: do you need to include the lookup tables (domain tables 'round my neck of the woods) in your queries? Presumably, these sorts of tables are usually

    • pretty static in nature — the domain might get extended, but it probably won't get shortened.
    • their primary key values are pretty unlikely to change as well (e.g., the status_id for a status of 'open' is unlikely to suddenly get changed to something other than what it was created as).

    If the above assumptions are correct, there's no real need to add all those extra tables to your joins just so your where clause can use a friend name instead of an id value. Just filter on status_id directly where you need to. I'd suspect the non-key attribute in the where clause ('name' in your example above) is more likely to get changes than the key attribute ('name' in your example above): you're more protected by referencing the desire key value(s) of the domain table in your join.

    Domain tables serve

    • to limit the domain of the variable via a foreign key relationship,
    • to allow the domain to be expanded by adding data to the domain table,
    • to populate UI controls and the like with user-friendly information,

    Naturally, you'd need to suck domain tables into your queries where you you actually required the non-key attributes from the domain table (e.g., descriptive name of the value).

    YMMV: a lot depends on context and the nature of the problem space.

提交回复
热议问题