Mysql - 许多 table 只提供 1 table 用于登录目的

Mysql - Many tables to come up with only 1 table for Login purposes

示例tables:

员工、客户和承包商

Contractor table 与 Employee 和 Customer 的工作方式相同,但有一些不同的字段 table

用途: 创建一个 User table 作为登录的基础。

提议用户table

User_ID     password     User_Type          
--------------------------------------------------------------------
Employee1    123*89       Employee       
Employee2    0123         Employee        
Customer1    12378        Customer       
Customer2    1234         Customer       
Contractor1  45678        Contractor      

员工 table:

ID          Firstname   Lastname   Address
--------------------------------------------------------------------
Employee1    Bon        Smith       123 North Street NY
Employee2    John       Doe         245 South Street NY

客户 table:

ID          Firstname   Lastname   Address
--------------------------------------------------------------------
Customer1    Ron        Price       123 North Street NY
Customer2    Peter      Doe         245 South Street NY

问题:


澄清:我想做的就是把不同tables(Employee, Customer and Contractor)的所有数据ID都放到1 table 用户.

我的建议

TABLE 用户角色

------------------------
ID   |    ROLENAME     |
 1   |    Employee
 2   |    Contractor   |
------------------------

TABLE 用户帐户

-------------------------------
ID USERNAME  PASSWORD USERROLE |
-------------------------------
1  employee1  password    1    |
2  Contractor password    2    |
--------------------------------

TABLE 雇员

--------------------------------------------
ID FIRSTNAME  LASTNAME  ADDRESS  USERACCOUNT|
--------------------------------------------|
1   FName      Lname    address     1       |
2   fname      lname    address     2       |
--------------------------------------------

TABLE 承包商

--------------------------------------------
ID FIRSTNAME  LASTNAME  ADDRESS  USERACCOUNT|
--------------------------------------------|
1   FName      Lname    address     1       |
2   fname      lname    address     2       |
--------------------------------------------

最好的做法是创建一个登录名 table 作为用户

User_ID 名称用户名密码角色

10 Ram1 ram12 123 员工
11 Ram2 ram14 456 雇员
13 Ram3 ram15 789 客户
14 Ram4 ram16 901 客户
15 Ram4 ram17 110 承包商

现在将 User_ID 作为主键将用户 ID 存储到其他 table 以建立关系

现在在 table 个帐户中 ::--

account_Iduser_Idaccount_no余额

1 10 123 19999 2 11 456 8723773
3 13 272 238738
4 14 2673 47437 5 15 3737 36732

如果你想要来自两个 table 的数据,那么加入两个 table 这意味着内部加入 (user.user_id = account.user_id)