[英]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.