简体   繁体   English

数据库表关系设计

[英]Database table relationship design

I am trying to write out a database design to include the following relationships, I have tried to work them out from the top down, hierarchically, but the relationships seem to be better connected another way, I just cannot see, or express how. 我试图写出一个数据库设计来包含以下关系,我试图从上至下按层次结构进行处理,但是这些关系似乎可以更好地通过另一种方式连接,我只是看不见或表达方式。

(This comes from a FOUO system from work, so the names have been changed to reflect that classification, that's why the names may look odd.) (这来自于工作中的FOUO系统,因此名称已经更改以反映该分类,这就是名称看起来可能奇怪的原因。)

Each Branch 1:n Functional Areas , 每个分支 1:n 功能区

Each Building 1:n Groups , 每个建筑物 1:n

Each Group 1:n Units , 1 :n 单元

Each FunctionalArea 1:n Checklists , 每个FunctionalArea 1:n 清单

Each Checklist 1:n Items , and 每个清单 1:n 项目 ,以及

Each Unit 1:n Checklists and 每个单元 1:n 清单

This was solved by re-evaluating the relationships without concern for the size or data type they would hold. 通过重新评估关系而不必担心它们将拥有的大小或数据类型来解决此问题。 1:n relationships were used in lieu of n:n. 使用1:n关系代替n:n。

one simple way I've used that would handle this is to have tables for each pairing: branch-function, building-function, building-group, group-unit, unit-checklist, checklist-item, keeping the objects and relationships separate. 我用来处理此问题的一种简单方法是为每个配对使用表:分支功能,建筑物功能,建筑物组,组单位,单位清单,清单项目,保持对象和关系分离。

It's basically tuple soup, but keeping that sorted is what a relational db is good at. 它基本上是元组汤,但是保持排序是关系型数据库最擅长的。 Accesses will be doing primary-key joins on multiple tables. 访问将在多个表上进行主键联接。 How large do you expect your dataset to grow? 您希望数据集增长多少?

The limits (100 checklists, etc) are policy. 限制(100个清单等)是政策。 Design the schema for simplicity and performance, implement policy in the application layer. 设计架构以简化和提高性能,并在应用程序层中实施策略。

When you are designing a database you need to be specific about the relationships. 在设计数据库时,需要具体说明它们之间的关系。 For example you need to mention things like "A functional area can only belongs to a one branch only". 例如,您需要提及诸如“功能区域只能属于一个分支”之类的事情。 These will help to determine either we are going to have 1:1 relations or 1:n or something else. 这些将有助于确定我们将要建立1:1关系或1:n关系。

However i have come up with an answer. 但是我想出了一个答案。 看图片

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM