简体   繁体   English

MYSQL:我应该为具有共同和不同字段的2种类型的用户使用2个表吗?

[英]MYSQL: should i use 2 tables for 2 types of user with common and different field?

i have 2 type of users 1. employee. 我有2种类型的用户1.员工。 2. employees friend. 2.员工朋友。

both users have common fields. 两个用户都有相同的字段。
1.first name 1.名字
2.middle name 2.中间名
3.surname 3.姓
4.cellphone number 4.手机号码
5.telephone number 5.电话号码
6.city address 6.城市地址
7.email (serve as login) 7.电子邮件(用作登录名)
8.password 8.密码
9.registration date 9.注册日期
10. update account date 10.更新帐户日期

and the employee friend user don't have this field 并且员工朋友用户没有此字段
1.employee id 1.员工编号
2.company name. 2.公司名称。
3.company branch 3.公司分公司
4.position 4.位置

and they will be going to use same login form. 他们将使用相同的登录表单。

edited version (thanks to nawfal and Patrick James McDougle) 编辑版本(感谢nawfal和Patrick James McDougle)

1st table (user) should contain field 1-10(first list) and a new field fk_employees (foreign key to our 2nd table, null if it is an employees_friend) 第一个表(用户)应包含字段1-10(第一个列表)和一个新字段fk_employees(第二个表的外键,如果为employee_friend,则为null

2nd table (employees) should contain field 1-4(second list) 第二个表(员工)应包含字段1-4(第二个列表)

I think about this the same way I think about object oriented programming. 我以同样的方式思考面向对象的编程。 If employee EXTENDS user then employee should be a user with extra information. 如果员工是EXTENDS用户,则员工应该是具有更多信息的用户。 I would have two tables. 我会有两个桌子。

Users (containing the common fields adding an id field perhaps) & Employees (with the 4 extra fields for employees and one field that references a unique identifier in the users table.) Users (可能包含添加ID字段的公共字段)和Employees (带有4个额外的员工字段,以及一个引用用户表中唯一标识符的字段)。

More information about what I am proposing can be found here: http://www.agiledata.org/essays/mappingObjects.html#MappingInheritance 有关我提出的建议的更多信息,请参见: http : //www.agiledata.org/essays/mappingObjects.html#MappingInheritance

what i suggest create 2 separate tables as users and user_friends with the fields mentioned above. 我建议使用上述字段创建2个单独的表,分别作为user和user_friends。

Now create a view with following query: 现在使用以下查询创建一个视图:

select employeeID,email,password from users
union
select friendID,email,password from user_friends

Query this view to get the login info in your application. 查询此视图以获取应用程序中的登录信息。

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

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