--作业2: --使用create table语句 创建学生成绩管理系统数据库6个表对象,逻辑结构见附图。 --1. 创建学院表 --2. 创建教师表 --3. 创建学生表 --4. 创建课程表 --5. 创建课堂表 --6. 创建上课表
时间: 2024-09-29 10:08:45 浏览: 39
创建学生成绩管理系统数据库六个表的对象通常涉及到数据库设计的基本步骤。以下是每个表的简单描述以及对应的SQL `CREATE TABLE` 语句示例:
1. **学院表 (Department)**
```sql
CREATE TABLE Department (
department_id INT PRIMARY KEY,
department_name VARCHAR(50) NOT NULL,
location VARCHAR(100)
);
```
2. **教师表 (Teacher)**
```sql
CREATE TABLE Teacher (
teacher_id INT PRIMARY KEY,
teacher_name VARCHAR(100),
department_id INT,
FOREIGN KEY (department_id) REFERENCES Department(department_id)
);
```
3. **学生表 (Student)**
```sql
CREATE TABLE Student (
student_id INT PRIMARY KEY,
student_name VARCHAR(100),
birth_date DATE,
gender CHAR(1),
department_id INT,
FOREIGN KEY (department_id) REFERENCES Department(department_id)
);
```
4. **课程表 (Course)**
```sql
CREATE TABLE Course (
course_id INT PRIMARY KEY,
course_name VARCHAR(100),
credit_hours INT,
department_id INT,
FOREIGN KEY (department_id) REFERENCES Department(department_id)
);
```
5. **课堂表 (Classroom)**
```sql
CREATE TABLE Classroom (
classroom_id INT PRIMARY KEY,
room_number VARCHAR(20),
capacity INT,
building_name VARCHAR(50)
);
```
6. **上课表 (Attendance)**
```sql
CREATE TABLE Attendance (
attendance_id INT PRIMARY KEY,
student_id INT,
teacher_id INT,
course_id INT,
classroom_id INT,
class_date DATE,
FOREIGN KEY (student_id) REFERENCES Student(student_id),
FOREIGN KEY (teacher_id) REFERENCES Teacher(teacher_id),
FOREIGN KEY (course_id) REFERENCES Course(course_id),
FOREIGN KEY (classroom_id) REFERENCES Classroom(classroom_id)
);
```
阅读全文