我有一个实验室分析数据库,我正在研究 bas 数据布局。我已经看到了一些基于使用“共享主键”的类似要求的建议,但我没有看到仅外键的优势。我正在使用 PostgreSQL:下面列出的表
Sample
___________
sample_id (PK)
sample_type (where in the process the sample came from)
sample_timestamp (when was the sample taken)
Analysis
___________
analysis_id (PK)
sample_id (FK references sample)
method (what analytical method was performed)
analysis_timestamp (when did the analysis take place)
analysis_notes
gc
____________
analysis_id (shared Primary key)
gc_concentration_meoh (methanol concentration)
gc_concentration_benzene (benzene concentration)
spectrophotometer
_____________
analysis_id
spectro_nm (wavelength used)
spectro_abs (absorbance measured)
我可以使用这种设计,或者我可以将分析表中的字段移动到 gc 和分光光度计表中,并在样品、gc 和分光光度计表之间使用外键。我看到的这种设计的唯一优势是,我只需要有关执行了多少或哪些类型的分析的信息,而不必加入实际结果。但是,确保共享主键之间的引用完整性以及管理额外连接和触发器(删除级联等)的附加规则似乎比次要优势更令人头疼。我不是 DBA,而是科学家,所以请让我知道我缺少什么。
更新:共享主键(据我所知)就像一对一的外键,具有附加约束,即父表(分析)中的每个值必须出现在其中一个子表中一次,并且不超过一次。