How do I reference a lookup table that might not contain the looked up record?

42 Views Asked by At

I’ve got a table that is a bit like reference data. But not contain all the reference data. Let’s call the table “labels” containing an id and label column.

Other business model tables can specify ids that may or may not be contained in the labels table.

When the UI displays the business model table data, if the id is in the labels table display the label value. Otherwise just display the id.

Also… there is a drop down to filter the data displayed on the page. The drop down contains the labels and unlabeled ids

So the table isn’t really reference data…

What kind of table is this?

1

There are 1 best solutions below

0
Julio Di Egidio -- inactive On BEST ANSWER

Well, what you describe is a dubious design more than a kind of table :), otherwise I would call it a "lookup" table: but I don't think there is anything particularly standard about this terminology.

To make it more concrete, what you describe is similar to what happens for example with translations, where the table of translated terms may be partial at any moment in time, i.e. not contain a translation for every possible term.

But the canonical way to approach that is to have the "lookup" table anyway be complete in that it contains all possible id's (all possible "terms"), just the associated "label" is nullable and stays NULL for as long as nobody provides the missing information.

The main difference with what you describe is that this way you can in fact have a proper FK from any table to this lookup table, while if the id's themselves may or may not be there, you cannot enforce any constraint on the id's used in other tables, not even the basic fact that there is a relationship there.

And, for what it's worth, and of course it is, that also has an impact on performances, since no FK usually means no optimization can be performed by the query engine on JOIN clauses and similar.