使用SQL语句创建班级表(class)、学生表(student)、选课表(s_c)和授课表(t_c)。(编写SQL语句)
时间: 2024-03-07 20:49:24 浏览: 451
以下是创建班级表、学生表、选课表和授课表的 SQL 语句:
创建班级表:
```
CREATE TABLE class (
class_id INT PRIMARY KEY,
class_name VARCHAR(50) NOT NULL,
class_teacher VARCHAR(50) NOT NULL
);
```
创建学生表:
```
CREATE TABLE student (
student_id INT PRIMARY KEY,
student_name VARCHAR(50) NOT NULL,
student_age INT NOT NULL,
student_gender VARCHAR(10) NOT NULL,
class_id INT NOT NULL,
FOREIGN KEY (class_id) REFERENCES class(class_id)
);
```
创建选课表:
```
CREATE TABLE s_c (
sc_id INT PRIMARY KEY,
student_id INT NOT NULL,
course_id INT NOT NULL,
FOREIGN KEY (student_id) REFERENCES student(student_id),
FOREIGN KEY (course_id) REFERENCES t_c(course_id)
);
```
创建授课表:
```
CREATE TABLE t_c (
tc_id INT PRIMARY KEY,
teacher_id INT NOT NULL,
course_id INT NOT NULL,
FOREIGN KEY (teacher_id) REFERENCES teacher(teacher_id),
FOREIGN KEY (course_id) REFERENCES course(course_id)
);
```
注意:以上 SQL 语句只是示例,具体实现需要根据具体需求进行调整。
阅读全文