[英]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.数据库的目标是存储所有人员(除了我们自己的员工),所有记录的公司(正规公司和商会成员),人员和公司的地址,员工目前负责的任务,列表我们的员工(用户)和房间内的角色。
person
works for one company
一个person
一家company
company
have multiple person
一个company
有多person
person
and company
can have multiple address
person
和company
可以有多个address
company
can be in multiple industry
一家company
可以在多个industry
industry
can have multiple company
一个industry
可以有多个company
company
can have multiple membertype
一个company
可以有多个membertype
membertype
can have multiple company
一个membertype
可以有多个company
user
can play multiple role
一个user
可以扮演多个role
role
can be assigned to mutliple user
一个role
可以分配给多个user
user
can have multiple task
一个user
可以有多个task
task
can be worked on by multiple user
一项task
可以由多个user
task
can target multiple person
一个task
可以针对多种person
person
can be targeted by multiple task
一个person
可以成为多项task
目标person
can only be added by one user
一个person
只能由一个user
添加user
can add multiple person
一个user
可以添加多个person
company
can have 0 or 1 parent_company
一家company
可以有 0 或 1 个parent_company
parent_company
can have multiple child company一个parent_company
可以有多个子公司I have come up with the following design and it has undergone some changes:我提出了以下设计,并进行了一些更改:
user-task-person
relationship?有没有更好的方式来显示user-task-person
关系?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"?它会被认为是“不洁”吗?membertype
, should company_id
and typename
both be PK?对于表membertype
, company_id
和typename
都应该是 PK 吗?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。
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.