建立教师表、课程表和选课表用SQL语句实现。
时间: 2024-02-17 17:00:17 浏览: 70
教师表:
```
CREATE TABLE teacher (
id INT PRIMARY KEY,
name VARCHAR(50),
gender VARCHAR(10),
age INT,
subject VARCHAR(50),
phone VARCHAR(20)
);
```
课程表:
```
CREATE TABLE course (
id INT PRIMARY KEY,
name VARCHAR(50),
teacher_id INT,
credit INT,
FOREIGN KEY (teacher_id) REFERENCES teacher(id)
);
```
选课表:
```
CREATE TABLE selection (
id INT PRIMARY KEY,
student_id INT,
course_id INT,
score INT,
FOREIGN KEY (student_id) REFERENCES student(id),
FOREIGN KEY (course_id) REFERENCES course(id)
);
```
相关问题
教师表、课程表和选课表用SQL语句实现。
教师表:
```
CREATE TABLE teacher (
id INT PRIMARY KEY,
name VARCHAR(50),
gender VARCHAR(10),
age INT,
subject VARCHAR(50),
phone VARCHAR(20)
);
```
课程表:
```
CREATE TABLE course (
id INT PRIMARY KEY,
name VARCHAR(50),
teacher_id INT,
credit INT,
FOREIGN KEY (teacher_id) REFERENCES teacher(id)
);
```
选课表:
```
CREATE TABLE selection (
id INT PRIMARY KEY,
student_id INT,
course_id INT,
score INT,
FOREIGN KEY (student_id) REFERENCES student(id),
FOREIGN KEY (course_id) REFERENCES course(id)
);
```
要求教师表、课程表和选课表用SQL语句实现
好的,以下是教师表、课程表和选课表的SQL语句实现:
1. 教师表
```
CREATE TABLE teacher (
teacher_id INT PRIMARY KEY,
teacher_name VARCHAR(50) NOT NULL,
teacher_gender ENUM('male', 'female') NOT NULL,
teacher_age INT NOT NULL,
teacher_phone VARCHAR(20) NOT NULL
);
```
2. 课程表
```
CREATE TABLE course (
course_id INT PRIMARY KEY,
course_name VARCHAR(50) NOT NULL,
course_teacher_id INT NOT NULL,
FOREIGN KEY (course_teacher_id) REFERENCES teacher (teacher_id)
);
```
3. 选课表
```
CREATE TABLE student_course (
student_id INT NOT NULL,
course_id INT NOT NULL,
PRIMARY KEY (student_id, course_id),
FOREIGN KEY (student_id) REFERENCES student (student_id),
FOREIGN KEY (course_id) REFERENCES course (course_id)
);
```
以上是教师表、课程表和选课表的SQL语句实现,如果您有其他问题,欢迎继续提问。
阅读全文