[英]Database table design best practice for update_date NOT NULL constraints
[英]What would be an appropriate table/database design for these constraints?
给定4张桌子,
表“基地”
表“实例”
表“修饰符”
表'base_has_modifier'
我试图对 model 的约束是,实例只能将修饰符绑定到其基础。
目前我有这个,
表“instance_has_base_modifier”
如您所见,这允许实例具有来自其他基础的修饰符。
现在的问题是,model 是否可以通过强制实例仅将修饰符标记到其基础的方式来实现? 如果是这样,怎么做? 如果不是,为什么?
谢谢你。
-- Base BAS exists.
--
base {BAS}
PK {BAS}
-- Base BAS has instance number INS#, of that base.
--
instance_ {BAS, INS#}
PK {BAS, INS#}
FK1 {BAS} REFERENCES base {BAS}
-- Modifier MOD exists.
--
modifier {MOD}
PK {MOD}
-- Modifier MOD applies to base BAS
--
base_mod {BAS, MOD}
PK {BAS, MOD}
FK1 {BAS} REFERENCES base {BAS}
FK2 {MOD} REFERENCES modifier {MOD}
如果基础修饰符适用于该基础的所有实例。
-- Modifier MOD applies to instance number INS# of base BAS.
--
CREATE VIEW inst_mod
AS
SELECT i.BAS
, i.INS#
, b.MOD
FROM instance_ AS i
JOIN base_mod AS b ON b.BAS = i.BAS ;
如果一个基础修饰符可能会或可能不会应用于该基础的实例。
-- Modifier MOD applies to instance number INS# of base BAS.
--
inst_mod {BAS, INS#, MOD}
PK {BAS, INS#, MOD}
FK1 {BAS, INS#} REFERENCES instance_ {BAS, INS#}
FK2 {BAS, MOD} REFERENCES base_mod {BAS, MOD}
笔记:
All attributes (columns) NOT NULL
PK = Primary Key
FK = Foreign Key
Using suffix # to save on screen space.
OK for SQL Server and Oracle, for others use _NO.
For example, rename INS# to INS_NO.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.