如何建模一个MySQL结构来处理身份验证?用户信息分离 [英] How to model a MySQL structure to deal with authentication? With users information separated
问题描述
我需要帮助为我的数据库建立一个表结构。
我有两张表:老师和学生。而要处理身份验证,我有
另一个表:user。我想保留关于老师和
学生的信息,分离有关登录信息(用户表)的信息。
例如:
老师
-----------------
| id |名称|
-----------------
| 10 | lorem |
| 20 | ipsum |
| 30 | dolor |
-----------------
student
------------ -----
| id |名称|
-----------------
| 5 | amet |
| 6 | sitt |
| 7 | dolum |
-----------------
信息分为两个表。
用户表:
user
------------- -------------------------------------------------- -
| id | teacher_id | student_id |登录|密码|
---------------------------------------------- -------------------
| 1 | 10 | | lorem_lo | ******* |
| 2 | 20 | | ipsum_lo | ******* |
| 3 | 30 | | dolor_lo | ******* |
| 4 | | 5 | amet_lo | ******* |
| 5 | | 6 | sitt_lo | ******* |
| 6 | | 7 | dolum_lo | ******* |
---------------------------------------------- -------------------
解决方案我以为是这样我问你的意见。
这是一个很好的解决方案吗?
提前感谢
PS:我正在使用要解除用户表中的空字段,您可以执行以下操作:
---------------------------------- ----------------
| id |用户|级|登录|密码|
---------------------------------------------- ----
其中 在这种情况下,您可以使用级别列在您的应用程序中创建访问。用户
包含所有您的学生和教师ID和级别
,其中包含教师和 2 $ c的
1
<另一种方法是使用一张表...分开学生和老师槽水平,但不是最佳实践。
I need help to model a table structure for my database.
I have two tables: teacher and student. And to deal with authentication, I have another table called: user. I want to maintain the information about teacher and student separated of the information about login (user table).
For example:
teacher
-----------------
| id | name |
-----------------
| 10 | lorem |
| 20 | ipsum |
| 30 | dolor |
-----------------
student
-----------------
| id | name |
-----------------
| 5 | amet |
| 6 | sitt |
| 7 | dolum |
-----------------
Information separated in two tables. The user table:
user
-----------------------------------------------------------------
| id | teacher_id | student_id | login | password |
-----------------------------------------------------------------
| 1 | 10 | | lorem_lo | ******* |
| 2 | 20 | | ipsum_lo | ******* |
| 3 | 30 | | dolor_lo | ******* |
| 4 | | 5 | amet_lo | ******* |
| 5 | | 6 | sitt_lo | ******* |
| 6 | | 7 | dolum_lo | ******* |
-----------------------------------------------------------------
The solution I thought was that. I ask your opinion about. Is that a good solution?
Thanks in advance.
P.S.: I'm using Mysql (InnoDB)
To eliminate empty fields from user table, you can do this:
--------------------------------------------------
| id | user | level | login | password |
--------------------------------------------------
where user
contains all your students and teachers ID's and level
that contains 1
for teachers and 2
for students.
In this case, you can use level column to create access in your app.
Another method, is with one table... separate students and teacher trough levels but isn't best practice.
这篇关于如何建模一个MySQL结构来处理身份验证?用户信息分离的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!