Database Design – Best Approach for Overriding Fields in a Database

database-design

I have a database that contains projects and each project contains many samples. I want a project level threshold value, to trigger highlighting when a field on the sample is above this threshold. I also want to be able to override the threshold at the individual sample level.

So I can see two ways to implement this:

  1. keep the threshold field (only) on the sample, and trigger this to get filled in when the project is saved.

  2. have both sample and project level threshold fields, and only use the sample field when it is relevant (there seems to be some redundancy with this model, though it more accurately represents the situation)?

Are there advantages / problems with either approach?

Best Answer

Its actually a simple descision based on how often you update the project threshold vs. how often you query the samples.

If the project level threshold is not updated very often then I would copy the threshold to every sample row (with perhaps an extra column to indicate an overridden value). This will make any queries simpler and faster.

On the other hand if you update the default threshold frequently. The keep it at the project level and take the (slight) performance hit for the join for every query.

Related Topic