mysql为数据库SchoolDB创建学生年级表Grade、信息表Student、课程表subject和成绩表Result;
时间: 2024-09-24 15:11:38 浏览: 46
在MySQL中,为了创建数据库名为"SchoolDB"的数据表,你需要分别执行以下SQL命令:
1. 学生年级表 Grade (假设年级字段包括grade_id, grade_name):
```sql
CREATE TABLE SchoolDB.Grade (
grade_id INT PRIMARY KEY,
grade_name VARCHAR(50) NOT NULL
);
```
2. 学生机息表 Student (可能包含student_id, student_name, grade_id等字段):
```sql
CREATE TABLE SchoolDB.Student (
student_id INT PRIMARY KEY,
student_name VARCHAR(100),
grade_id INT,
FOREIGN KEY (grade_id) REFERENCES Grade(grade_id)
);
```
3. 课程表 Subject (假设包含subject_id, subject_name):
```sql
CREATE TABLE SchoolDB.Subject (
subject_id INT PRIMARY KEY,
subject_name VARCHAR(100)
);
```
4. 成绩表 Result (包含result_id, student_id, subject_id, score等字段):
```sql
CREATE TABLE SchoolDB.Result (
result_id INT PRIMARY KEY,
student_id INT,
subject_id INT,
score DECIMAL(3,1),
FOREIGN KEY (student_id) REFERENCES Student(student_id),
FOREIGN KEY (subject_id) REFERENCES Subject(subject_id)
);
```
这些建表语句会按照需求为"SchoolDB"数据库建立基础的表结构,以便存储学生、年级、课程以及成绩信息。
阅读全文