简体   繁体   English

我应该将组织表分成两个表吗?

[英]Should I split my organizations table into two tables?

I'm designing the database schema for a CRM. 我正在为CRM设计数据库模式。 It has the following tables: users , organizations , contacts , addresses , organization_types . 它具有下表: usersorganizationscontactsaddressesorganization_types

organizations might be a company, a non-profit or a individual. organizations可以是公司,非营利组织或个人。

users have a many to many relationship with organizations . usersorganizations有多对多关系。 The reason is because one company, for example, can have a salesman and a manager on the app with two different logins. 原因是因为,例如,一家公司可以在应用程序上有一名销售员和一名经理,并使用两种不同的登录名。 On the other hand, there is the possibility that a salesman is doing sales for two different companies. 另一方面,推销员有可能为两家不同的公司进行销售。

contact and addresses have a one to one relationship with organizations . contactaddressesorganizations具有一对一的关系。 My client only want a organization to have one of each of those. 我的客户只希望一个组织拥有其中一个。

I designed it in a way that a organization can also be a client, that would belong to another organization . 我以一种organization也可以是另一个organization的客户的方式设计它。 That would mean that the organization table had a one to many relationship with itself. 这意味着组织表与其自身具有一对多的关系。

That made sense to me because they seem to be the same entity. 这对我来说很有意义,因为它们似乎是同一实体。 A client will also need a contacts and addresses table and it could also be a company, non-profit or individual. 客户还将需要一个contactsaddresses表,该表也可以是公司,非营利组织或个人。

The point to consider that another developer raised is that with time, it would be expensive to query the database to differentiate organizations that are our clients from the ones that are clients from our clients. 考虑另一个开发人员提出的要点是,随着时间的流逝,查询数据库以区分作为我们客户的组织与作为我们客户的组织的组织将是昂贵的。

What is the best approach? 最好的方法是什么? Would it be better the make a client_organizations table and separate those two? 制作一个client_organizations表并将两者分开会更好吗?

I will keep one table and create a column named parent_organization. 我将保留一个表并创建一个名为parent_organization的列。 Parent_organization will be nullable and store primary key of parent organization that child organizations belong to Parent_organization将为空,并存储子组织所属的父组织的主键

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

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