One database I recently start working with was designed with one main table containing all possible values, and foreign keys in other tables are specifying the nature of each of those items.
CREATE TABLE entity
(
indexid INTEGER PRIMARY KEY NOT NULL,
entitytype INTEGER,
entityname VARCHAR,
);
For example, this main table contain a field named 'entityname' possibly containing records such as:
- the upc code of the item
- the short name of the item
- the long name of the item
- the location of the item
- the vendor for this item
- the quantity in stock
- (and many others)
Each record in this table got a entitytype number as a foreign key referring in another table what each records mean, such as
entitytype=10 mean that this entity is a UPC code type, and then
entitytype=12 mean that this entity is a vendor name type, etc...
Obviously there is dozen of such types for entities.
I feel like it is a bit unintuitive. There is this post here (See One table to hold all domain values section) where the author suggest the approach as I expressed it in my example may not be the best way to do this, and I would tend to agree with his opinion on the matter.
I also think it is difficult to make efficient queries, and I feel it is not how this should be done. I would rather have more tables and keep the whole more intuitive. I have a time window where I could redesign this and was thinking about long term and best practices.
So can this approach be considered a good practice in the long term and I just need to deal with it?