Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 两个相似用户的数据库模式_Mysql_Database_Logging_Schema - Fatal编程技术网

Mysql 两个相似用户的数据库模式

Mysql 两个相似用户的数据库模式,mysql,database,logging,schema,Mysql,Database,Logging,Schema,我对我正在制作的DB模式有疑问。 我有两个相似的用户,但其中一个比另一个有更多的信息: Type 1 : Administrator - Name - Lastname - Email - Password Type 2: Student - Name - Lastname - Email - Password - Status - Sex - Among other type of personal information fields 所以,我犹豫是否要创建这两个单独的表,当它们要登录时

我对我正在制作的DB模式有疑问。 我有两个相似的用户,但其中一个比另一个有更多的信息:

Type 1 : Administrator
- Name
- Lastname
- Email
- Password

Type 2: Student
- Name
- Lastname
- Email
- Password
- Status
- Sex
- Among other type of personal information fields
所以,我犹豫是否要创建这两个单独的表,当它们要登录时,查询它们(因为我只有一个日志屏幕),或者将它们统一为一个表用户,然后创建另一个名为“extra”的表,其中用户的外键指向后者


实现这一目标最有效的方法是什么?感谢您抽出时间

我将制作两个表,并在登录后进行连接。在用户登录后缓存有关用户的额外事实

您应该有一个包含以下列的
User
表:

Id、姓名、姓氏、电子邮件、密码、IsAdmin

使用学生桌:

UserId、状态、性别等

学生
也必须是
用户
——这将减少数据重复

如果您需要比
IsAdmin
更多的权限,请删除该列并创建
UserPermissions
Permission


如果您真的非常关心连接,那么只需在一个
User
表中使所有内容都为空即可。我怀疑这在您的用例中是否重要(这是一个更大的主题)。

管理员是一个人扮演的角色

学生是一个人扮演的角色

一个人可以一次扮演一个角色,也可以一次扮演多个角色。这是一条业务规则,不应考虑到数据库架构中

用于在同一表中允许不同类型的角色

create table people (
  person_id int primary key,
  given_name varchar(...),
  surname varchar(...),
  password varchar(...)--consider a `users` table instead
);

create table roles (
  role_id int primary key,
  person_id int not null references people(person_id), --use the long-hand foreign key syntax for mysql
  type varchar(...),    --admin or student
  status varchar(...),  --consider PostgreSQL over mysql, as it supports check constraints
  sex varchar(...)
);