用于存储不同类型“人”的SQL数据库设计
我需要使用 SQL 在关系数据库中为具有 Name
、LastName
等列的人员创建一个表。
我将拥有三种不同类型的人:卖家、买家和客户。
每个人都有其他信息/属性。
我是否需要为每种不同类型的人员创建一个表,还是可以为所有三种类型使用一个表?
如果我使用单个表,如果一种类型的“人员”(例如卖方)具有与另一种人员类型不同的属性怎么办?
I need to create a table in a relational database using SQL for persons having the columns Name
, LastName
and so on.
I'll have three different kinds of People: Seller, Buyer and Customer.
Every person has other information/attributes.
Do I need to create a table for each different type of Person or can a single table be used for all three types?
If I used a single table, what if one type of "Person", say Seller, has different attributes from another Person type?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我将创建一个表 Person ,以 personId 作为主键,其中将包含所有类型的公共属性。(卖方、买方、客户)
然后我将创建 PersonTypes,这是一个小型参考表,它将声明不同类型的代码。
然后,对于每种类型,我将参考 Person 表创建一个单独的表,并
包含所有唯一属性的 PersonType 表。
I would create one table Person , with personId as primary key that will contain common properties for all types.(Seller , Buyer , Customer)
Then I would create PersonTypes, a small reference table , that will declare codes for the different types .
Then for each type I would create a separate table with reference to Person table and
PersonType table that includes all the unique properties.
您可以创建 1 个或两个表。当然,您可以为每个用户角色创建 3 个表。这取决于您想要实现的目标。您的问题的常见解决方案是:创建两张表,一张用于用户,一张用于其角色(mysql 示例:
You can create 1 or two tables. Of course you can create 3 tables for each user role. It depend's on what you would like to achieve. Common solution to your question is: create two tables, one for users and one for their roles (examples for mysql:
卖家可以成为买家或客户吗?如果可以的话,将它们全部放在同一个表中,这样您就不会拥有相同数据的单独副本。
Can a seller ever be a buyer or a customer? If they can, put it all in the same table so that you don't have separate copies of the same data.