1,新建三张表,分别为班级表(classes),学生表(student),学生成绩表(student_score) 对应的字段如下: 班级表: 班级id(class_id),班级名称(class_name),创建时间(create_time) 学生表: 班级id(class_id),学生id(stu_id),学生姓名(stu_name),年龄(age),性别(sex),家庭住址(address),生日(brithday) 学生成绩表: 班级id(class_id),学生id(stu_id),分数(score) 交付内容:三张表的完整建表语句,每张表需包含主键或者索引。
时间: 2023-08-07 18:03:56 浏览: 117
ll(1)fenxi.rar_LL(1) 语法分析_语法树_预测分析表法
5星 · 资源好评率100%
班级表(classes)建表语句:
```
CREATE TABLE classes (
class_id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
class_name VARCHAR(50) NOT NULL,
create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
```
学生表(student)建表语句:
```
CREATE TABLE student (
class_id INT NOT NULL,
stu_id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
stu_name VARCHAR(50) NOT NULL,
age INT NOT NULL,
sex ENUM('M', 'F') NOT NULL,
address VARCHAR(100) NOT NULL,
birthday DATE NOT NULL,
INDEX(class_id),
FOREIGN KEY (class_id) REFERENCES classes(class_id)
);
```
学生成绩表(student_score)建表语句:
```
CREATE TABLE student_score (
class_id INT NOT NULL,
stu_id INT NOT NULL,
score DECIMAL(5,2) NOT NULL,
PRIMARY KEY (class_id, stu_id),
INDEX (class_id),
FOREIGN KEY (class_id) REFERENCES classes(class_id),
FOREIGN KEY (stu_id) REFERENCES student(stu_id)
);
```
阅读全文