人->详细数据库结构

发布于 2024-08-06 19:51:55 字数 232 浏览 6 评论 0原文

我有一个域模型:
员工:身份证、名字、姓氏、性别、出生日期。
办公室:员工、工作站、办公室名称等。
联系人:员工、手机、电子邮件等...

但我不确定我当前的数据库结构。如何正确:员工表有一个 PK EmployeeID,办公室和联系人表有自己的 ID 和对员工表的引用,或者员工表有自己的 EmployeeID,并且还通过拥有 OfficeID 和 ContactID 来保留对办公室和联系人的引用?

I have a Domain model:
Employee: Id, FirstName, LastName, Sex, BirthDate.
Office: Employee, WorkStation, OfficeName, etc..
Contacts: Employee, MobilePhone, EMail, etc...

But I`m not sure about my current database structure. How is right: Employees table has a PK EmployeeID, and the Offices and Contacts tables has their own IDs and reference to Employees table, OR Employees table has its EmployeeID and also keeps references to Offices and Contscts by having OfficeID and ContactID?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

爱给你人给你 2024-08-13 19:51:55

为了保持合理的正常形式,您的员工应咨询办公室。

假设联系人关系是员工拥有一组联系人,并且没有其他员工共享这些联系人,则正确的关系应该是联系人引用该员工。

员工:empid、officeid

办公室:officeid

联系人:empid、contactid

To be in a reasonable normal form, your employees should refer to the office.

Assuming the relationship of contacts is employees have a set of contacts and no other employee shares those contacts, the proper relationship should be contacts refer to the employee.

Employee: empid, officeid

Office: officeid

Contacts: empid, contactid

风月客 2024-08-13 19:51:55

如果 Office 和 Contact 表中的数据只是增强有关 Employee 的信息,我会使用 EmployeeID 作为 Employee 的主键和外键。该模型模拟了 1 到 0..1 的关系。

员工:员工 ID 作为主键

办公室和联系人:员工 ID 作为员工的主键和外键

If data in Office and Contact table just enhance information about Employee, I would use EmployeeID as primary key and foreign key to Employee. That models 1 to 0..1 relation.

Employee: EmployeeID as primary key

Office and Contacts: EmployeeID as primary key and foreign key to Employee

温柔一刀 2024-08-13 19:51:55

您的模型没有明确说明员工、办公室和联系人之间的关系。
具体来说,这些关系是一对一、一对多还是多对多?一旦您对想要建模的关系进行了分类,数据库的外键结构就会变得清晰。

Your model is not explicit about the relationships between Employees, Offices, and Contacts.
Specifically, are these relationships one-to-one, one-to-many, or many-to-many? Once you've catalogued the relationships you want modeled, the foreign key structure of your database will become clear.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文