使用sql语句创建学生系统数据库有系部(department)、学生(student)、课程(course)、选修(stud_course)、老师(teacher)五个表格。
时间: 2024-11-27 21:20:17 浏览: 22
创建一个包含系部、学生、课程、选修和老师五张表的学生系统数据库,可以分别使用SQL创建各表的命令来完成。这里给出基本的创建表结构的示例:
1. 系部 (Department) 表:
```sql
CREATE TABLE Department (
dept_id INT PRIMARY KEY,
dept_name VARCHAR(50) NOT NULL
);
```
2. 学生 (Student) 表:
```sql
CREATE TABLE Student (
student_id INT PRIMARY KEY,
student_name VARCHAR(50),
student_email VARCHAR(100),
dept_id INT,
FOREIGN KEY (dept_id) REFERENCES Department(dept_id)
);
```
3. 课程 (Course) 表:
```sql
CREATE TABLE Course (
course_id INT PRIMARY KEY,
course_title VARCHAR(100),
teacher_id INT
);
```
4. 选修 (Stud_Course) 表(也叫 Enrollment 或者 Course_Taken):
```sql
CREATE TABLE Stud_Course (
student_id INT,
course_id INT,
grade FLOAT,
PRIMARY KEY (student_id, course_id),
FOREIGN KEY (student_id) REFERENCES Student(student_id),
FOREIGN KEY (course_id) REFERENCES Course(course_id)
);
```
5. 老师 (Teacher) 表:
```sql
CREATE TABLE Teacher (
teacher_id INT PRIMARY KEY,
teacher_name VARCHAR(50),
department_id INT,
FOREIGN KEY (department_id) REFERENCES Department(dept_id)
);
```
阅读全文