我现在要设计一个学生管理系统的数据库,要求如下:1.有三种身份的人,分别是教务老师,科任老师和学生。2.我们的数据有很多,分别是:班级、学号、密码、姓名、性别、班级、科目、科目成绩。请问你如何用mysql代码设计出来呢
时间: 2023-06-06 13:06:21 浏览: 135
可以按照以下的格式设计出一个学生管理系统的数据库:
CREATE DATABASE student_management_system;
USE student_management_system;
--创建教务老师表
CREATE TABLE admin (
id INT AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(30) NOT NULL,
password VARCHAR(30) NOT NULL
);
--创建科任老师表
CREATE TABLE teacher (
id INT AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(30) NOT NULL,
password VARCHAR(30) NOT NULL,
class_id INT NOT NULL,
subject VARCHAR(30) NOT NULL
);
--创建学生表
CREATE TABLE student (
id INT AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(30) NOT NULL,
password VARCHAR(30) NOT NULL,
class_id INT NOT NULL,
name VARCHAR(30) NOT NULL,
gender ENUM('男', '女') NOT NULL
);
--创建班级表
CREATE TABLE class (
id INT AUTO_INCREMENT PRIMARY KEY,
class_name VARCHAR(30) NOT NULL,
admin_id INT NOT NULL
);
--创建科目表
CREATE TABLE subject (
id INT AUTO_INCREMENT PRIMARY KEY,
subject_name VARCHAR(30) NOT NULL
);
--创建成绩表
CREATE TABLE score (
id INT AUTO_INCREMENT PRIMARY KEY,
student_id INT NOT NULL,
subject_id INT NOT NULL,
score FLOAT NOT NULL
);
--添加测试数据
INSERT INTO admin (username, password)
VALUES ('admin', 'admin');
INSERT INTO class (class_name, admin_id)
VALUES ('一年级1班', 1),
('一年级2班', 1),
('二年级1班', 1),
('二年级2班', 1);
INSERT INTO subject (subject_name)
VALUES ('语文'),
('数学'),
('英语'),
('物理'),
('化学');
INSERT INTO teacher (username, password, class_id, subject)
VALUES ('teacher1', 'teacher1', 1, '语文'),
('teacher2', 'teacher2', 1, '数学'),
('teacher3', 'teacher3', 2, '语文'),
('teacher4', 'teacher4', 2, '数学'),
('teacher5', 'teacher5', 3, '英语'),
('teacher6', 'teacher6', 4, '化学'),
('teacher7', 'teacher7', 4, '物理');
INSERT INTO student (username, password, class_id, name, gender)
VALUES ('student1', 'student1', 1, '张三', '男'),
('student2', 'student2', 1, '李四', '女'),
('student3', 'student3', 2, '王五', '男'),
('student4', 'student4', 2, '赵六', '女'),
('student5', 'student5', 3, '周七', '男'),
('student6', 'student6', 3, '钱八', '女'),
('student7', 'student7', 4, '孙九', '男'),
('student8', 'student8', 4, '吴十', '女');
INSERT INTO score (student_id, subject_id, score)
VALUES (1, 1, 90),
(1, 2, 90),
(1, 3, 80),
(1, 4, 70),
(1, 5, 60),
(2, 1, 80),
(2, 2, 70),
(2, 3, 85),
(2, 4, 90),
(2, 5, 70),
(3, 1, 60),
(3, 2, 70),
(3, 3, 80),
(3, 4, 70),
(3, 5, 60),
(4, 1, 80),
(4, 2, 90),
(4, 3, 95),
(4, 4, 85),
(4, 5, 80),
(5, 1, 70),
(5, 2, 80),
(5, 3, 85),
(5, 4, 90),
(5, 5, 75),
(6, 1, 90),
(6, 2, 80),
(6, 3, 75),
(6, 4, 70),
(6, 5, 80),
(7, 1, 80),
(7, 2, 85),
(7, 3, 90),
(7, 4, 80),
(7, 5, 75),
(8, 1, 85),
(8, 2, 90),
(8, 3, 80),
(8, 4, 70),
(8, 5, 90);
以上是一个简单的学生管理系统的数据库设计,可以使用mysql语句来创建和操作相关的表和数据。数据表中包括教务老师(admin)表,科任老师(teacher)表,学生(student)表,班级(class)表,科目(subject)表和成绩(score)表,可以根据这些表来对学生信息和成绩进行相关的查询和管理。
阅读全文