标签:练习题 inno drop ons 练习 course gen varchar 外键
表关系: 下面每个表的第一个字段是主键,未建立外键,使用逻辑外键
班级表
DROP TABLE IF EXISTS `
class
`;
CREATE TABLE `
class
` (
`cid`
int
(
11
) NOT NULL AUTO_INCREMENT,
`caption` varchar(
255
) NOT NULL,
`grade_id`
int
(
11
) NOT NULL,
PRIMARY KEY (`cid`)
) ENGINE
=
InnoDB AUTO_INCREMENT
=
16
DEFAULT CHARSET
=
utf8;
DROP TABLE IF EXISTS `class_grade`;
CREATE TABLE `class_grade` (
`gid`
int
(
11
) NOT NULL AUTO_INCREMENT,
`gname` varchar(
255
) NOT NULL,
PRIMARY KEY (`gid`)
) ENGINE
=
InnoDB AUTO_INCREMENT
=
7
DEFAULT CHARSET
=
utf8;
DROP TABLE IF EXISTS `course`;
CREATE TABLE `course` (
`cid`
int
(
11
) NOT NULL,
`cname` varchar(
255
) NOT NULL,
`teacher_id`
int
(
11
) NOT NULL,
PRIMARY KEY (`cid`)
) ENGINE
=
InnoDB DEFAULT CHARSET
=
utf8;
DROP TABLE IF EXISTS `score`;
CREATE TABLE `score` (
`sid`
int
(
11
) NOT NULL AUTO_INCREMENT,
`student_id`
int
(
11
) NOT NULL,
`course_id`
int
(
11
) NOT NULL,
`score` varchar(
255
) DEFAULT NULL,
PRIMARY KEY (`sid`)
) ENGINE
=
InnoDB AUTO_INCREMENT
=
20
DEFAULT CHARSET
=
utf8;
DROP TABLE IF EXISTS `student`;
CREATE TABLE `student` (
`sid`
int
(
11
) NOT NULL AUTO_INCREMENT,
`sname` varchar(
255
) NOT NULL,
`gender` enum(
‘女‘
,
‘男‘
) NOT NULL DEFAULT
‘男‘
,
`class_id`
int
(
11
) NOT NULL,
PRIMARY KEY (`sid`)
) ENGINE
=
InnoDB AUTO_INCREMENT
=
17
DEFAULT CHARSET
=
utf8;
DROP TABLE IF EXISTS `teacher`;
CREATE TABLE `teacher` (
`tid`
int
(
11
) NOT NULL,
`tname` varchar(
255
) DEFAULT NULL,
PRIMARY KEY (`tid`)
) ENGINE
=
InnoDB DEFAULT CHARSET
=
utf8;
DROP TABLE IF EXISTS `teacher2cls`;
CREATE TABLE `teacher2cls` (
`tcid`
int
(
11
) NOT NULL AUTO_INCREMENT,
`tid`
int
(
11
) NOT NULL,
`cid`
int
(
11
) NOT NULL,
PRIMARY KEY (`tcid`)
) ENGINE
=
InnoDB AUTO_INCREMENT
=
8
DEFAULT CHARSET
=
utf8;
1.查询“生物”课程和“物理”课程成绩都及格的学生id和姓名;
2.查询每个年级的班级数,取出班级数最多的前三个年级;
3.查询每位学生的学号,姓名,选课数,平均成绩;
4.查询每个年级的学生人数;
标签:练习题 inno drop ons 练习 course gen varchar 外键
原文地址:https://www.cnblogs.com/chriszun/p/12642749.html