学生信息数据库的创建
创作时间:
作者:
@小白创作中心
学生信息数据库的创建
引用
CSDN
1.
https://m.blog.csdn.net/qq_63781342/article/details/144331629
需求分析
学生信息数据库用于存储学生相关信息,包括学生所在院系、学生基础信息、老师信息、学生总成绩、学生各学科成绩以及专业课基础信息。系统需要构建不同用户角色,并为每个角色分配不同的权限,以维护整个数据库。例如,班主任负责维护学生总成绩,各科老师管理各科成绩表及专业基础表,学生用户可以填写和查看自己的基础信息。
关系模型分析
表结构设计
学生基本信息表
基本信息字段 | 数值类型 | 约束 |
|---|---|---|
id | int | primary key |
name | varchar(20) | not null |
gender | set('male','female') | null |
age | int | null |
number | varchar(20) | unique |
join_time | date | null |
phone | varchar(20) | null |
教师基本信息表
基本信息字段 | 数值类型 | 约束 |
|---|---|---|
id | int | primary key |
name | varchar(20) | not null |
gender | set('male','female') | null |
phone | varchar(20) | null |
subject | set('math','chine','english') | null |
专业基本信息表
基本信息字段 | 数值类型 | 约束 |
|---|---|---|
id | int | primary |
name | varchar(20) | not null |
total | int | not null |
department | varchar(20) | not null |
学科基本信息表
基本信息字段 | 数值类型 | 约束 |
|---|---|---|
id | int | primary key |
name | set('english','math','china') | null |
time | int | default |
total | int | not |
teacher | varchar(20) | null |
总成绩表
基本信息字段 | 数值类型 | 约束 |
|---|---|---|
id | int | primary key |
std_id | int | foreign key |
score | float | not null |
ranking | int | not null |
各科成绩表
基本信息字段 | 数值类型 | 约束 |
|---|---|---|
id | int | primary key |
std_id | int | foreign key |
suj_id | int | foreign key |
score | float | not null |
数据库物理设计与实现
创建数据库并使用
create database if not exists student_database charset utf8mb4;
use student_database;
创建数据表
学生表
create table student_table(
id int primary key,
name varchar(20) not null,
gender set('female','male'),
age int,
number varchar(20) unique,
join_time date,
phone varchar(20)
);
教师表
create table teacher_table(
id int primary key,
name varchar(20) not null,
gender set('male','female'),
phone varchar(20),
subject set('math','english','china')
);
专业表
create table major_table(
id int primary key,
name varchar(20) not null,
total int not null,
department varchar(20) not null
);
学科表
create table subject_table(
id int primary key,
name set('english','math','china'),
time int default 48,
total int,
teacher varchar(20)
);
成绩表
总成绩表
create table total_score_table(
id int primary key,
std_id int,
score float not null,
ranking int not null,
constraint fk_std_id foreign key (std_id) references student_table(id)
);
各科成绩表
create table score_table(
id int primary key,
std_id int,
sub_id int,
score float,
constraint fk_std_new_id foreign key (std_id) references student_table(id),
constraint fk_sub_id foreign key (sub_id) references subject_table(id)
);
创建用户并进行授权
用户管理相关语法
查询用户
select * from mysql.user;
创建用户
create user 'user_a'@'localhost' identified by 'old_mima';
修改用户密码
alter user 'user_a'@'localhost' identified by 'new_mima';
删除用户
drop user 'user_a'@'localhost';
权限管理相关语法
查询权限
show grants for 'root'@'localhost';
授予权限
#创建新用户
create user 'user_a'@'localhost' identified by 'old_mima';
#授予权限
grant all privileges on student_database.student_table to 'user_a'@'localhost';
撤销权限
remove all privileges on student_database.student_table from 'user_a'@'localhost';
创建相应角色
使用不同角色插入数据来模拟数据库的使用与维护
学生
此处应该创建多个学生来进行学生基础信息表的维护,但是所使用的命令相近,因此仅创建一个作为演示。
创建
create user 'student'@'localhost' identified by 'student';
授权
grant all privileges on student_database.student_table to 'student'@'localhost';
老师
此处老师也仅适用一个进行演示
create user 'teacher'@'localhost' identified by 'teacher';
GRANT ALL PRIVILEGES ON student_database.teacher_table TO 'teacher'@'localhost';
GRANT ALL PRIVILEGES ON student_database.subject_table TO 'teacher'@'localhost';
GRANT ALL PRIVILEGES ON student_database.score_table TO 'teacher'@'localhost';
班主任
创建角色
create user 'master'@'localhost' identified by 'master';
授予权限
班主任授予全部数据表的权限,可以直接使用*代替
grant all privileges on student_database.* to 'master'@'localhost';
数据库的使用
学生
使用student用户登录,发现student_database中仅仅可以使用student_table
老师
使用teacher用户登录,可以使用student_database中的teacher_table,score_table和subject_table三个表
班主任
使用master用户登录,可以使用student_database中的所有表
热门推荐
票拟与批红:明朝内阁制度的演变
明太祖朱元璋的治国理念:严明法治与民生关怀
AI/AR产业链深度协同!浙大系四企联手开启AI/AR新时代
提升产品质量的可靠性试验方法与技巧
中国古典诗词中的思念之美:从空间阻隔到时光流逝
大连上榜中国十大“美好宜居”城市
1.2436模具钢的用途X210CrW12特性(圆钢、板材)
止咳中成药大全 怎么选止咳中成药
双11商家投诉报告:“任意仅退款”占比超六成
多地回暖冲30℃ 但厚衣服先别收 3月初降温最低0℃
乡村生态旅游景观资源开发与规划设计原则分析
柯凡vs詹姆斯:从不当言论到停职反思
身体湿气太重怎么办?医生推荐这三个解决方案
霍林郭勒市:智慧办税新生态引领枫桥办税新模式
蜂蜜与奶粉能一起喝吗?专家解读饮用注意事项
@广大城乡居民 请不要轻易放弃自己的医保待遇
31省汇总:2025年全国高考时间科目表!含2025新高考时间表
中国制造业:从“世界工厂”到“制造强国”的转型之路
最高1.8万!杭州加大汽车以旧换新补贴力度 小米SU7要排队等20周
若无移民,八年后美国将出现人口负增长
新形势下打击治理跨境网络赌博犯罪策略研究
应该怎样正确服用健胃消食片
健康指南:肝囊肿的全面解析
智能家居:从概念到落地,全方位解析其技术、应用与未来走向
列车暂停发售还会开吗?暂停发售≠停运!揭秘列车背后的秘密调整
山口百惠:昭和时代的樱花女神
多地已积雪!刚刚确认:杭州雨雪升级!请密切关注预报
车都停满了,凌晨大批杭州人往这赶!最强雨雪来袭,重要提醒请收好
边境牧羊犬训练指南:从基础到进阶的全面教程
NBA传奇卡特退役,收到前篮网传奇人物的暖心信息