What is the best approach for overriding fields in a database?

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?

2

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.

Your 2nd option provides the most flexibility with minimal extra complexity.

In the sample record, have a nullable field that holds the local threshold level. Set the field to null if the sample is to use the default threshold from the project. If you are using SQL, it is straight-forward to join the tables and use isnull to grab the threshold value:

SELECT Field1, Field2, ISNULL(sample.threshold, project.threshold) as Threshold FROM ...

I would go with your second option, only store the override value on the sample records when it is different to the project threshold (stored on the project record).

These seems like the cleaner solution to me (storing info about the project with the project record, and the sample specific data with the sample) but more importantly there’s a problem with your first option.

For example, if you store the project threshold on the samples where there is no sample specific threshold and you have a project threshold of 5:

| Sample Name | Threshold | 
| Sample A    | 5         | 
| Sample B    | 5         | 
| Sample C    | 5         | 

You update Sample C to have an over-ridden threshold of 6:

| Sample Name | Threshold |
| Sample A    | 5         |
| Sample B    | 5         |
| Sample C    | 6         |

You then update the project threshold to 6:

| Sample Name | Threshold |
| Sample A    | 6         |
| Sample B    | 6         |
| Sample C    | 6         |

If you should go on to change the project threshold back down, you can’t distinguish C from A and B, meaning it will also be changed back to 5, which might not be what you want.

You could store a flag to indicate that the threshold is sample specific to avoid this situation, but this seems redundant when compared to storing the project threshold on the project and having nulls in the sample threshold unless it is set.

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật