创建学生信息相关表,插入测试数据
# 年级表
CREATE TABLE `grade` (
`grade_id` int(11) NOT NULL AUTO_INCREMENT COMMENT '年级自增主键ID',
`name` varchar(12) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '年级名',
PRIMARY KEY (`grade_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
# 插入数据
insert into `grade`(`grade_id`,`name`) values (1,'小学一年级'),(2,'小学二年级'),(3,'小学三年级'),(4,'小学四年级'),(5,'小学五年级'),(6,'小学六年级');
# 班级表
CREATE TABLE `class` (
`class_id` int(11) NOT NULL AUTO_INCREMENT COMMENT '班级自增主键ID',
`name` varchar(12) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '班级名',
`grade_id` int(11) NOT NULL COMMENT '年级ID',
PRIMARY KEY (`class_id`),
KEY `class_ifbk_1` (`grade_id`),
CONSTRAINT `class_ifbk_1` FOREIGN KEY (`grade_id`) REFERENCES `grade` (`grade_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
#插入数据
insert into `class`(`class_id`,`name`,`grade_id`) values (1,'1班',1),(2,'2班',1),(3,'3班',1),(4,'4班',1),(5,'5班',1),(6,'6班',1),
(7,'1班',2),(8,'2班',2),(9,'3班',2),(10,'4班',2),(11,'5班',2),(12,'6班',2),(13,'1班',3),(14,'2班',3),(15,'3班',3),(16,'4班',3),
(17,'5班',3),(18,'1班',4),(19,'2班',4),(20,'3班',4),(21,'4班',4),(22,'5班',4),(23,'1班',5),(24,'2班',5),(25,'3班',5),(26,'4班',5),
(27,'5班',5),(28,'1班',6),(29,'2班',6),(30,'3班',6),(31,'4班',6);
# 学生表
CREATE TABLE `students` (
`stu_id` int(11) NOT NULL AUTO_INCREMENT COMMENT '学生自增主键ID',
`name` varchar(24) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '学生姓名',
`class_id` int(11) NOT NULL COMMENT '班级ID',
`gender` tinyint(1) unsigned NOT NULL DEFAULT '1' COMMENT '学生性别,1=男生,2=女生',
`age` tinyint(2) unsigned NOT NULL COMMENT '学生年龄',
PRIMARY KEY (`stu_id`),
KEY `students_ibfk_1` (`class_id`),
CONSTRAINT `students_ibfk_1` FOREIGN KEY (`class_id`) REFERENCES `class` (`class_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
#插入数据
insert into `students`(`stu_id`,`name`,`class_id`,`gender`,`age`) values (227,'包不同',3,1,8),(228,'郁光标',1,1,7),(229,'幽草',6,2,7),
(230,'融智大师',2,2,7),(231,'老贾',5,2,7),(232,'完颜阿骨打',1,1,8),(233,'辛双清',5,2,7),(234,'单伯山',1,2,7),(235,'孟师叔',6,1,6),
(236,'宋长老',6,2,8),(237,'刀白凤',2,1,7),(238,'于洞主',4,2,8),(239,'智光大师',3,1,6),(240,'苏辙',6,2,7),(241,'风波恶',6,1,6),
(242,'无崖子',5,1,6),(243,'天山童姥',6,2,6),(244,'司马林',5,1,6),(245,'芙蓉仙子崔绿华',3,1,8),(246,'康广陵',3,2,6),(247,'龚光杰',2,2,8),
(248,'葛光佩',6,1,6),(249,'竹剑',1,2,6),(250,'耶律重元',6,2,7),(251,'许卓诚',5,1,6),(252,'梦姑',3,1,7),(253,'诸保昆',1,2,6),
(254,'秦伯起',1,2,6),(255,'徐长老',1,1,8),(256,'海风子',6,2,6),(257,'阿洪',2,1,6),(258,'祁六',1,1,8),(259,'易大彪',2,2,7),
(260,'范百龄',3,2,7),(261,'玄生',6,2,6),(262,'玄慈',6,1,6),(263,'颇拉苏',5,1,6),(264,'慕容复',2,1,8),(265,'章虚道长',4,2,6),
(266,'玄难',5,2,7),(267,'古笃诚',2,2,8),(268,'黎夫人',3,2,7),(269,'破疑',2,2,8),(270,'陈长老',4,1,7),(271,'刘竹庄',5,1,6),
(272,'耶律涅鲁古',2,2,6),(273,'阿碧',6,2,6);
# 课程表
CREATE TABLE `subject` (
`subject_id` int(11) NOT NULL AUTO_INCREMENT COMMENT '科目自增主键ID',
`name` varchar(32) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '科目名称',
PRIMARY KEY (`subject_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
# 插入数据
insert into `subject`(`subject_id`,`name`) values (1,'语文'),(2,'数学'),(3,'体育'),(4,'艺术'),(5,'综合实践活动'),(6,'品德与生活'),(7,'品德与社会'),(21,'科学');;
# 课程与班级关联表
CREATE TABLE `subject_grade` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '自增主键ID',
`subject_id` int(11) NOT NULL COMMENT '科目ID',
`grade_id` int(11) NOT NULL COMMENT '年级ID',
PRIMARY KEY (`id`),
KEY `subject_grade_ibfk_1` (`subject_id`),
KEY `subject_class_ibfk_1` (`grade_id`),
CONSTRAINT `subject_class_ibfk_1` FOREIGN KEY (`grade_id`) REFERENCES `grade` (`grade_id`),
CONSTRAINT `subject_grade_ibfk_1` FOREIGN KEY (`subject_id`) REFERENCES `subject` (`subject_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
#插入数据
insert into `subject_grade`(`id`,`subject_id`,`grade_id`) values (1,1,6),(2,2,6),(3,3,6),(4,4,6),(5,5,6),(6,6,6),(52,1,1),(53,2,1),
(54,3,1),(55,4,1),(56,5,1),(57,6,1),(58,1,4),(59,2,4),(60,3,4),(61,4,4),(62,5,4),(63,7,4),(64,21,4),(65,1,5),(66,2,5),(67,3,5),(68,4,5),
(69,5,5),(70,7,5),(71,21,5),(72,1,3),(73,2,3),(74,3,3),(75,4,3),(76,5,3),(77,7,3),(78,21,3),(79,1,2),(80,2,2),(81,3,2),(82,4,2),
(83,5,2),84,6,2);
# 学生成绩表
CREATE TABLE `score` (
`score_id` int(11) NOT NULL AUTO_INCREMENT COMMENT '成绩自增主键',
`stu_id` int(11) NOT NULL COMMENT '学生ID',
`subject_id` int(11) NOT NULL COMMENT '科目ID',
`score` tinyint(3) NOT NULL COMMENT '学生成绩',
PRIMARY KEY (`score_id`),
KEY `score_stu_ibfk_1` (`stu_id`),
KEY `score_subject_ibfk_1` (`subject_id`),
CONSTRAINT `score_stu_ibfk_1` FOREIGN KEY (`stu_id`) REFERENCES `students` (`stu_id`),
CONSTRAINT `score_subject_ibfk_1` FOREIGN KEY (`subject_id`) REFERENCES `subject` (`subject_id`)
) ENGINE=InnoDB AUTO_INCREMENT=13344 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
# 插入数据、
insert into `score`(`score_id`,`stu_id`,`subject_id`,`score`) values (1,227,1,48),(2,227,2,59),(3,227,3,72),
(4,227,4,95),(5,227,5,85),(6,227,6,80),(7,228,1,88),(8,228,2,67),(9,228,3,73),(10,228,4,40),(11,228,5,67),
(12,228,6,80),(13,229,1,84),(14,229,2,82),(15,229,3,61),(16,229,4,52),(17,229,5,66),(18,229,6,81),(19,230,1,72),
(20,230,2,53),(21,230,3,66),(22,230,4,40),(23,230,5,98),(24,230,6,67),(25,231,1,75),(26,231,2,67),(27,231,3,41),
(28,231,4,50),(29,231,5,98),(30,231,6,99),(31,232,1,71),(32,232,2,99),(33,232,3,81),(34,232,4,83),(35,232,5,60),
(36,232,6,76),(37,233,1,42),(38,233,2,42),(39,233,3,76),(40,233,4,67),(41,233,5,61),(42,233,6,59),(43,234,1,71),
(44,234,2,51),(45,234,3,59),(46,234,4,76),(47,234,5,93),(48,234,6,90),(49,235,1,93),(50,235,2,52),(51,235,3,98),
(52,235,4,57),(53,235,5,83),(54,235,6,85),(55,236,1,71),(56,236,2,97),(57,236,3,53),(58,236,4,59),(59,236,5,67),
(60,236,6,49),(61,237,1,93),(62,237,2,90),(63,237,3,100),(64,237,4,55),(65,237,5,94),(66,237,6,76),(67,238,1,60),
(68,238,2,93),(69,238,3,91),(70,238,4,46),(71,238,5,98),(72,238,6,70),(73,239,1,71),(74,239,2,68),(75,239,3,40),
(76,239,4,78),(77,239,5,53),(78,239,6,50),(79,240,1,67),(80,240,2,99),(81,240,3,49),(82,240,4,50),(83,240,5,40),
(84,240,6,83),(85,241,1,93),(86,241,2,59),(87,241,3,70),(88,241,4,98),(89,241,5,70),(90,241,6,59),(91,242,1,68),
(92,242,2,60),(93,242,3,88),(94,242,4,92),(95,242,5,55),(96,242,6,43),(97,243,1,50),(98,243,2,51),(99,243,3,62),
(100,243,4,75),(101,243,5,69),(102,243,6,53),(103,244,1,53),(104,244,2,62),(105,244,3,91),(106,244,4,97),
(107,244,5,63),(108,244,6,75),(109,245,1,78),(110,245,2,71),(111,245,3,80),(112,245,4,51),(113,245,5,47),
(114,245,6,75),(115,246,1,41),(116,246,2,82),(117,246,3,59),(118,246,4,77),(119,246,5,85),(120,246,6,49),
(121,247,1,48),(122,247,2,98),(123,247,3,97),(124,247,4,93),(125,247,5,94),(126,247,6,55),(127,248,1,77),
(128,248,2,76),(129,248,3,68),(130,248,4,65),(131,248,5,64),(132,248,6,91),(133,249,1,75),(134,249,2,46),
(135,249,3,70),(136,249,4,98),(137,249,5,96),(138,249,6,58),(139,250,1,53),(140,250,2,47),(141,250,3,69),
(142,250,4,78),(143,250,5,57),(144,250,6,99),(145,251,1,53),(146,251,2,78),(147,251,3,55),(148,251,4,92),
(149,251,5,75),(150,251,6,79),(151,252,1,55),(152,252,2,64),(153,252,3,67),(154,252,4,45),(155,252,5,89),
(156,252,6,79),(157,253,1,87),(158,253,2,49),(159,253,3,56),(160,253,4,49),(161,253,5,42),(162,253,6,79),
(163,254,1,54),(164,254,2,57),(165,254,3,63),(166,254,4,51),(167,254,5,67),(168,254,6,81),(169,255,1,68),
(170,255,2,48),(171,255,3,97),(172,255,4,53),(173,255,5,56),(174,255,6,99),(175,256,1,69),(176,256,2,69),
(177,256,3,42),(178,256,4,79),(179,256,5,92),(180,256,6,47),(181,257,1,50),(182,257,2,92),(183,257,3,89),
(184,257,4,71),(185,257,5,49),(186,257,6,99),(187,258,1,56),(188,258,2,71),(189,258,3,86),(190,258,4,94),
(191,258,5,89),(192,258,6,55),(193,259,1,49),(194,259,2,67),(195,259,3,79),(196,259,4,76),(197,259,5,67),
(198,259,6,67),(199,260,1,65),(200,260,2,56),(201,260,3,73),(202,260,4,76),(203,260,5,51),(204,260,6,73),
(205,261,1,90),(206,261,2,74),(207,261,3,81),(208,261,4,69),(209,261,5,67),(210,261,6,51),(211,262,1,91),
(212,262,2,70),(213,262,3,85),(214,262,4,40),(215,262,5,73),(216,262,6,51),(217,263,1,62),(218,263,2,69),
(219,263,3,85),(220,263,4,80),(221,263,5,60),(222,263,6,58),(223,264,1,57),(224,264,2,100),(225,264,3,62),
(226,264,4,56),(227,264,5,56),(228,264,6,100),(229,265,1,83),(230,265,2,41),(231,265,3,44),(232,265,4,53),
(233,265,5,91),(234,265,6,84),(235,266,1,65),(236,266,2,69),(237,266,3,77),(238,266,4,96),(239,266,5,56),
(240,266,6,89),(241,267,1,47),(242,267,2,70),(243,267,3,54),(244,267,4,61),(245,267,5,65),(246,267,6,65),
(247,268,1,91),(248,268,2,69),(249,268,3,41),(250,268,4,56),(251,268,5,45),(252,268,6,74),(253,269,1,64),
(254,269,2,67),(255,269,3,90),(256,269,4,71),(257,269,5,67),(258,269,6,72),(259,270,1,40),(260,270,2,83),
(261,270,3,41),(262,270,4,90),(263,270,5,52),(264,270,6,45),(265,271,1,83),(266,271,2,55),(267,271,3,60),
(268,271,4,70),(269,271,5,59),(270,271,6,84),(271,272,1,76),(272,272,2,58),(273,272,3,64),(274,272,4,87),
(275,272,5,85),(276,272,6,41),(277,273,1,50),(278,273,2,86),(279,273,3,85),(280,273,4,44),(281,273,5,79),
(282,273,6,62);