简体   繁体   English

对联系人管理数据库设计的建议

[英]Suggestion for a contact management database design

I am currently designing a contact management database for a chamber of commerce.我目前正在为商会设计联系人管理数据库。 The goal of the database is to store all the person (except our own staff), all recorded companies (regular companies and member of the chamber), addresses of the person and companies, tasks that the staff are currently responsible for, a list of our staff ( user ) and the roles within the chamber.数据库的目标是存储所有人员(除了我们自己的员工),所有记录的公司(正规公司和商会成员),人员和公司的地址,员工目前负责的任务,列表我们的员工(用户)和房间内的角色


Business Rules商业规则

  • one person works for one company一个person一家company
  • one company have multiple person一个company有多person
  • person and company can have multiple address personcompany可以有多个address
  • one company can be in multiple industry一家company可以在多个industry
  • one industry can have multiple company一个industry可以有多个company
  • one company can have multiple membertype一个company可以有多个membertype
  • one membertype can have multiple company一个membertype可以有多个company
  • one user can play multiple role一个user可以扮演多个role
  • one role can be assigned to mutliple user一个role可以分配给多个user
  • one user can have multiple task一个user可以有多个task
  • one task can be worked on by multiple user一项task可以由多个user
  • one task can target multiple person一个task可以针对多种person
  • one person can be targeted by multiple task一个person可以成为多项task目标
  • one person can only be added by one user一个person只能由一个user添加
  • one user can add multiple person一个user可以添加多个person
  • one company can have 0 or 1 parent_company一家company可以有 0 或 1 个parent_company
  • one parent_company can have multiple child company一个parent_company可以有多个子公司

I have come up with the following design and it has undergone some changes:我提出了以下设计,并进行了一些更改:

在此处输入图片说明

Issue问题

  • Are there better ways to display the user-task-person relationship?有没有更好的方式来显示user-task-person关系?
  • For example, if a person can have only one email but can have multiple tel , should I make an extra table just for tel while email is still in the person table?例如,如果一个person只能有email但可以有多个tel ,我是否应该在email仍在person表中时为tel创建一个额外的表? Would it considered to be "unclean"?它会被认为是“不洁”吗?
  • For the table membertype , should company_id and typename both be PK?对于表membertypecompany_idtypename都应该是 PK 吗?
  • How does this schema look now?这个模式现在看起来如何? Are there still some normalisations to be done?是否还有一些规范化工作要做?

I'm a newbee at database, there are definitely some design flaws or errors, it would be nice if you guys could give me some suggestions so that I can correct and improve this design.我是数据库的新手,肯定有一些设计缺陷或错误,如果你们能给我一些建议,以便我可以纠正和改进这个设计,那就太好了。 Thank you ^~^谢谢^~^

The main issue I see is that while all primary keys are defined as Int some foreign keys or references are defined as varchar.我看到的主要问题是,虽然所有主键都定义为 Int,但一些外键或引用被定义为 varchar。

  1. company in contact table联系表中的公司
  2. user_role in user table用户表中的 user_role
  3. parent_company in company母公司在公司
  4. added_by in user table用户表中的 added_by

Also role_id is length 10 while all other primary keys are 11.同样 role_id 的长度为 10,而所有其他主键的长度均为 11。
Personally I would prefer capitalised table names, User, Company etc我个人更喜欢大写的表名、用户、公司等

Update for the edited version:已编辑版本的更新:

You might want to create a table for phone, mail,fax etc say contact_info that could contain a string field holding the contact info and a type field (email, phone, fax,...).您可能想要为电话、邮件、传真等创建一个表,比如contact_info ,它可以包含一个包含联系信息的字符串字段和一个类型字段(电子邮件、电话、传真等)。 This way you could store several phone numbers for instance, if you want to limit email to one you could either leave it in the person table and not allow it here or have a business rule to only allow one email row in contact_info .通过这种方式,您可以存储多个电话号码,例如,如果您想将电子邮件限制为一个,您可以将其保留在person表中并且不允许在此处使用,或者有一个业务规则只允许在contact_info一个电子邮件行。

This table could also be useful for company if you want to store email or phone numbers for the company like contact@somecompany.com or the number to the company switchboard此表也可能是有用的company ,如果你想存储电子邮件或电话号码的company像contact@somecompany.com或公司总机数

For the table membertype, should company_id and typename both be PK?对于表成员类型,company_id 和 typename 都应该是 PK 吗?

Yes是的

Second update About the address solution: Shouldn't the address table contain enough info to make each address unique, I can understand that a company can have more than one address but should it allowed for two companies to have the same address (by that I mean the same row in the database) so maybe it should be changed to a one-to-many from company and ´address´ but a one-to-one in the other direction.第二次更新关于地址解决方案: address表是否应该包含足够的信息来使每个地址唯一,我可以理解一家公司可以有多个地址,但是否允许两家公司拥有相同的地址(通过我意味着数据库中的同一行)所以也许它应该从company和“地址”改为一对多,但在另一个方向是一对一。
I also think it could be good to have some kind of label in the two address-link tables so one can easily identify an address like "home", "work", "Office", "Warehouse"...我还认为在两个地址链接表中添加某种标签可能会很好,这样人们就可以轻松识别诸如“家”、“工作”、“办公室”、“仓库”之类的地址......

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

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