学生学籍管理系统my sql代码
时间: 2023-10-15 20:04:24 浏览: 135
以下是一个简单的学生学籍管理系统的MySQL代码,包括了学生信息、学籍信息、成绩信息、教师信息、课程信息和班级信息的表结构和数据:
```sql
-- 学生信息表
CREATE TABLE IF NOT EXISTS `student` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(50) NOT NULL,
`gender` varchar(10) NOT NULL,
`age` int(11) NOT NULL,
`hometown` varchar(50) DEFAULT NULL,
`phone` varchar(20) DEFAULT NULL,
`email` varchar(50) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- 学籍信息表
CREATE TABLE IF NOT EXISTS `school_roll` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`student_id` int(11) NOT NULL,
`class_id` int(11) NOT NULL,
`major` varchar(50) NOT NULL,
`enrollment_date` date NOT NULL,
`graduation_date` date DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `student_id` (`student_id`),
KEY `class_id` (`class_id`),
CONSTRAINT `school_roll_ibfk_1` FOREIGN KEY (`student_id`) REFERENCES `student` (`id`) ON DELETE CASCADE,
CONSTRAINT `school_roll_ibfk_2` FOREIGN KEY (`class_id`) REFERENCES `class` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- 成绩信息表
CREATE TABLE IF NOT EXISTS `score` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`student_id` int(11) NOT NULL,
`course_id` int(11) NOT NULL,
`score` float NOT NULL,
PRIMARY KEY (`id`),
KEY `student_id` (`student_id`),
KEY `course_id` (`course_id`),
CONSTRAINT `score_ibfk_1` FOREIGN KEY (`student_id`) REFERENCES `student` (`id`) ON DELETE CASCADE,
CONSTRAINT `score_ibfk_2` FOREIGN KEY (`course_id`) REFERENCES `course` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- 教师信息表
CREATE TABLE IF NOT EXISTS `teacher` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(50) NOT NULL,
`gender` varchar(10) NOT NULL,
`age` int(11) NOT NULL,
`phone` varchar(20) DEFAULT NULL,
`email` varchar(50) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- 课程信息表
CREATE TABLE IF NOT EXISTS `course` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(50) NOT NULL,
`credit` float NOT NULL,
`teacher_id` int(11) NOT NULL,
PRIMARY KEY (`id`),
KEY `teacher_id` (`teacher_id`),
CONSTRAINT `course_ibfk_1` FOREIGN KEY (`teacher_id`) REFERENCES `teacher` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- 班级信息表
CREATE TABLE IF NOT EXISTS `class` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(50) NOT NULL,
`teacher_id` int(11) NOT NULL,
PRIMARY KEY (`id`),
KEY `teacher_id` (`teacher_id`),
CONSTRAINT `class_ibfk_1` FOREIGN KEY (`teacher_id`) REFERENCES `teacher` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- 插入学生信息
INSERT INTO `student` (`id`, `name`, `gender`, `age`, `hometown`, `phone`, `email`) VALUES
(1, '张三', '男', 20, '北京市', '13888888888', 'zhangsan@qq.com'),
(2, '李四', '女', 21, '上海市', '13999999999', 'lisi@qq.com');
-- 插入班级信息
INSERT INTO `class` (`id`, `name`, `teacher_id`) VALUES
(1, '计算机1班', 1),
(2, '计算机2班', 2);
-- 插入教师信息
INSERT INTO `teacher` (`id`, `name`, `gender`, `age`, `phone`, `email`) VALUES
(1, '王老师', '男', 35, '13666666666', 'wang@qq.com'),
(2, '李老师', '女', 30, '13777777777', 'li@qq.com');
-- 插入课程信息
INSERT INTO `course` (`id`, `name`, `credit`, `teacher_id`) VALUES
(1, '数据库原理', 3, 1),
(2, 'Java编程', 4, 2);
-- 插入学籍信息
INSERT INTO `school_roll` (`id`, `student_id`, `class_id`, `major`, `enrollment_date`, `graduation_date`) VALUES
(1, 1, 1, '计算机科学与技术', '2020-09-01', NULL),
(2, 2, 2, '软件工程', '2020-09-01', NULL);
-- 插入成绩信息
INSERT INTO `score` (`id`, `student_id`, `course_id`, `score`) VALUES
(1, 1, 1, 90),
(2, 1, 2, 85),
(3, 2, 1, 88),
(4, 2, 2, 92);
```
以上是一个简单的学生学籍管理系统的MySQL代码,仅供参考。实际项目中还需要根据具体需求进行更加细致的设计和优化。
阅读全文