网络设备和配置的数据库模式设计
Database schema design for network devices and configuration
我有以下数据库设计问题:
给定四种实体类型:Interface
、Device
、VLAN
、VNI
。
有以下规则:
- 一个
Interface
正好有一个Device
。因此,Device
可能有零到多个 Interfaces
.
- 一个
Interface
可以有零到多个 VLAN
。一个 VLAN
可以有零到多个 Interfaces
。一个 VLAN
不能多次分配给同一个 Interface
。
- 一个
VLAN
可以有零个或一个VNI
。因此 VNI
有零到多个 VLAN
。
到目前为止这很容易,可以这样建模:
Interface(id, device_id not null)
Device(id)
VLAN(id, vni_id nullable)
VNI(id)
InterfaceVLAN(interface_id not null, vlan_id not null) unique (interface_id, vlan_id)
但是还有第四条规则:元组 (VNI
, Device
, VLAN
) 必须是唯一的。
还必须可以将 VLAN
分配给 VNI
,而不会将 VLAN
分配给 Interface
或 Device
。此外,VLAN
可以分配给 Interface
而 VLAN
没有 VNI
。
我对如何将其合并到模型中感到困惑,欢迎提出任何建议。
也许你可以试试唯一约束。假设你有一个 DEVICE
table 有一个 DEVICE_ID
列作为主键和一个 'VNI_ID` 列作为外键,那么你可以创建一个唯一约束这两列。
来自问题:
The tuple (VNI, Device, VLAN)
must be unique.
来自您对 James Hu 的评论:
Each VNI should map to no more than one VLAN on each Device.
这是两个不同的约束。第二个表示 (Device, VNI)
是唯一的,它表示第一个,但反之则不然。
-- Vni tag VNI exists.
--
vni_tag {VNI}
PK {VNI}
-- Virtual lan (vlan) VLN exists.
--
vlan {VLN}
PK {VLN}
- 每个vlan映射到最多一个 vni标签;
对于每个 vni 标记,该标记 可能 映射到 多个 vlan。
-- Vlan VLN is mapped to vni tag VNI.
--
vln_vni {VLN, VNI}
PK {VLN}
SK {VLN, VNI}
FK1 {VLN} REFERENCES vlan {VLN}
FK2 {VNI} REFERENCES vni_tag {VNI}
- 每个设备可能有多个接口;
对于每个接口:该接口属于 一个 设备。
-- Device DEV exists.
--
device {DEV}
PK {DEV}
-- Interface number IFC# of device DEV exists.
--
interface {DEV, IFC#}
PK {DEV, IFC#}
FK {DEV} REFERENCES device {DEV}
唯一(DEV、VNI)
在第二个约束的情况下,(DEV, VNI) unique:
每个接口可以连接到多个 vlan;
对于每个 vlan,多个接口可能连接到该 vlan。
对于设备和 vni 标签的每个组合,该设备和标签的组合最多只能出现一次。
-- Interface number IFC# of device DEV is connected to
-- vlan VLN, which is mapped to vni tag VNI.
--
ifc_vln_vni {DEV, IFC#, VLN, VNI}
PK {DEV, IFC#, VLN}
AK {DEV, VNI}
FK1 {DEV, IFC#} REFERENCES interface {DEV, IFC#}
FK2 {VLN, VNI} REFERENCES vln_vni {VLN, VNI}
唯一(DEV、VLN、VNI)
在第一个约束的情况下,(DEV, VLN, VNI) unique:
每个接口可以连接到多个 vlan;
对于每个 vlan,多个接口可能连接到该 vlan。
对于设备、vlan 和 vni 标签的每个组合,该设备、vlan 和标签的组合最多只能出现一次。
-- Interface number IFC# of device DEV is connected to
-- vlan VLN, which is mapped to vni tag VNI.
--
ifc_vln_vni {DEV, IFC#, VLN, VNI}
PK {DEV, IFC#, VLN}
AK {DEV, VLN, VNI}
FK1 {DEV, IFC#} REFERENCES interface {DEV, IFC#}
FK2 {VLN, VNI} REFERENCES vln_vni {VLN, VNI}
注:
All attributes (columns) NOT NULL
PK = Primary Key
SK = Proper Superkey (Unique)
AK = Alternate Key (Unique)
FK = Foreign Key
Using suffix # to save on screen space.
OK for SQL Server and Oracle, for others use _NO.
For example, rename IFC# to IFC_NO.
我有以下数据库设计问题:
给定四种实体类型:Interface
、Device
、VLAN
、VNI
。
有以下规则:
- 一个
Interface
正好有一个Device
。因此,Device
可能有零到多个Interfaces
. - 一个
Interface
可以有零到多个VLAN
。一个VLAN
可以有零到多个Interfaces
。一个VLAN
不能多次分配给同一个Interface
。 - 一个
VLAN
可以有零个或一个VNI
。因此VNI
有零到多个VLAN
。
到目前为止这很容易,可以这样建模:
Interface(id, device_id not null)
Device(id)
VLAN(id, vni_id nullable)
VNI(id)
InterfaceVLAN(interface_id not null, vlan_id not null) unique (interface_id, vlan_id)
但是还有第四条规则:元组 (VNI
, Device
, VLAN
) 必须是唯一的。
还必须可以将 VLAN
分配给 VNI
,而不会将 VLAN
分配给 Interface
或 Device
。此外,VLAN
可以分配给 Interface
而 VLAN
没有 VNI
。
我对如何将其合并到模型中感到困惑,欢迎提出任何建议。
也许你可以试试唯一约束。假设你有一个 DEVICE
table 有一个 DEVICE_ID
列作为主键和一个 'VNI_ID` 列作为外键,那么你可以创建一个唯一约束这两列。
来自问题:
The tuple
(VNI, Device, VLAN)
must be unique.
来自您对 James Hu 的评论:
Each VNI should map to no more than one VLAN on each Device.
这是两个不同的约束。第二个表示 (Device, VNI)
是唯一的,它表示第一个,但反之则不然。
-- Vni tag VNI exists.
--
vni_tag {VNI}
PK {VNI}
-- Virtual lan (vlan) VLN exists.
--
vlan {VLN}
PK {VLN}
- 每个vlan映射到最多一个 vni标签; 对于每个 vni 标记,该标记 可能 映射到 多个 vlan。
-- Vlan VLN is mapped to vni tag VNI.
--
vln_vni {VLN, VNI}
PK {VLN}
SK {VLN, VNI}
FK1 {VLN} REFERENCES vlan {VLN}
FK2 {VNI} REFERENCES vni_tag {VNI}
- 每个设备可能有多个接口;
对于每个接口:该接口属于 一个 设备。
-- Device DEV exists.
--
device {DEV}
PK {DEV}
-- Interface number IFC# of device DEV exists.
--
interface {DEV, IFC#}
PK {DEV, IFC#}
FK {DEV} REFERENCES device {DEV}
唯一(DEV、VNI)
在第二个约束的情况下,(DEV, VNI) unique:
每个接口可以连接到多个 vlan; 对于每个 vlan,多个接口可能连接到该 vlan。
对于设备和 vni 标签的每个组合,该设备和标签的组合最多只能出现一次。
-- Interface number IFC# of device DEV is connected to
-- vlan VLN, which is mapped to vni tag VNI.
--
ifc_vln_vni {DEV, IFC#, VLN, VNI}
PK {DEV, IFC#, VLN}
AK {DEV, VNI}
FK1 {DEV, IFC#} REFERENCES interface {DEV, IFC#}
FK2 {VLN, VNI} REFERENCES vln_vni {VLN, VNI}
唯一(DEV、VLN、VNI)
在第一个约束的情况下,(DEV, VLN, VNI) unique:
每个接口可以连接到多个 vlan; 对于每个 vlan,多个接口可能连接到该 vlan。
对于设备、vlan 和 vni 标签的每个组合,该设备、vlan 和标签的组合最多只能出现一次。
-- Interface number IFC# of device DEV is connected to
-- vlan VLN, which is mapped to vni tag VNI.
--
ifc_vln_vni {DEV, IFC#, VLN, VNI}
PK {DEV, IFC#, VLN}
AK {DEV, VLN, VNI}
FK1 {DEV, IFC#} REFERENCES interface {DEV, IFC#}
FK2 {VLN, VNI} REFERENCES vln_vni {VLN, VNI}
注:
All attributes (columns) NOT NULL
PK = Primary Key
SK = Proper Superkey (Unique)
AK = Alternate Key (Unique)
FK = Foreign Key
Using suffix # to save on screen space.
OK for SQL Server and Oracle, for others use _NO.
For example, rename IFC# to IFC_NO.