问题描述
我已经设法让我的数据库有些设计。到目前为止,它看起来像下面的
I have managed to get my database somewhat designed. So far, it looks like the following
这是场景。焦点是我的项目表。项目属于单个客户端。所以我可能创造一个项目说SO。这个项目可以有许多用户(图像显示错误的关系)在项目上工作。这些用户中的每一个属于一个部门。所以我和Bob可能正在为一个项目工作,我属于市场营销,Bob属于财务。
This is the scenario. The focal point is my projects table. A project belongs to a single client. So I might create a project for say SO. This project can have many users (image shows wrong relationship) that work on the project. Each of these users belongs to a department. So me and Bob may be working on a project for SO, I belong to Marketing and Bob belongs to Finance.
这里是我困惑的地方。每个部门都有一套文件,它需要为一个项目完成。营销可能需要做一个文档a和文档B,并且财务可能需要做一个文档C.
Here is where I am getting confused. Each department has a set of documents it needs to complete for a project. Marketing might need to do a Document a and Document B, and finance might need to do a Document C.
说我做这样的事情
Say I do something like this
我基本上是说一个部门有一个或多个文件。但是,然后你可以看到它变得凌乱。如何显示市场营销有documentA和documentB,财务有document3?
I am basically saying that a department has one or more documents. But then you can see it gets messy. How can I show that Marketing has documentA and documentB and Finance has documentThree?
我需要将营销和财务定义为与departments表的一对一关系,那么文件来自这个?这将产生类似
Would I need to define marketing and finance as a one to one relationship with the departments table, and then do documents coming from this? That would produce something along the lines of this
这是正确的方法吗?基本上,我需要将不同的文档链接到不同的部门,什么是最好的方式来实现这个?
Is that the correct approach to be taking? Essentially, I need to link different documents to different departments, what would be the best way to achieve this?
感谢
推荐答案
我个人不喜欢任何一种方法;因为当表中的数据几乎类型相同时,它们为每个文档类型创建单独的表。在这些情况下,我会更喜欢一个表。
Personally I don't like either approach; as they create separate tables for each doc type when the data in the tables is nearly typed the same. I would be more in favor of one table in these cases.
我会有一个文档表,其中有一个类型,表示文档类型,并且是DocumentType的前键其中列出所有文档类型。
I would have a documents table with a type in it which indicates document type and is a forein key to DocumentType table which lists all document types.
根据为项目和部门选择的文档类型,我会有一个DepartmentDocuments表,其中列出了每个部门可以使用的文档。我还将有一个ProjectDepartmentDocuments表,它指示用于特定项目的强制和可选文档,以及特定于部门/项目的信息。
Depending on how document types are chosen for project and department, I would have a DepartmentDocuments table which list the documents which each department COULD use. I would also have a ProjectDepartmentDocuments table which indicates the mandated and optional documents used for a particular project, along with their information specific to the department/project.
我也质疑用户和项目之间的关系。看来一个项目只能有一个用户。如果是这样,你的设计是好的。但是,如果一个项目可以有很多用户,你应该有一个projectUsers表来处理多对多关系。
I also question the relationship from users to projects. It appears a project can only have one user. If that's the case your design is fine. However if a project can have many users, you should have a projectUsers table to handle many-to-many relationships.
这篇关于数据库设计指南的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!