sql
复制代码
-- 创建学生表
CREATE TABLE students (
student_id INT PRIMARY KEY AUTO_INCREMENT,
studentname VARCHAR(50),
age INT,
gender VARCHAR(10)
);
-- 创建课程表
CREATE TABLE courses (
course_id INT PRIMARY KEY AUTO_INCREMENT,
course_name VARCHAR(50)
);
-- 创建教师表
CREATE TABLE teachers (
teacher_id INT PRIMARY KEY AUTO_INCREMENT,
teachername VARCHAR(50),
department VARCHAR(50)
);
-- 创建成绩表
CREATE TABLE grades (
grade_id INT PRIMARY KEY AUTO_INCREMENT,
student_id INT,
course_id INT,
grade DECIMAL(5, 2),
FOREIGN KEY (student_id) REFERENCES students(student_id),
FOREIGN KEY (course_id) REFERENCES courses(course_id)
);
-- 创建授课表
CREATE TABLE teachings (
teaching_id INT PRIMARY KEY AUTO_INCREMENT,
teacher_id INT,
course_id INT,
FOREIGN KEY (teacher_id) REFERENCES teachers(teacher_id),
FOREIGN KEY (course_id) REFERENCES courses(course_id)
);
sql
复制代码
-- 插入学生数据
INSERT INTO students (name, age, gender)
VALUES ('张三', 18, '男'),
('李四', 19, '女'),
('王五', 20, '男');
-- 插入课程数据
INSERT INTO courses (course_name)
VALUES ('数学'),
('英语'),
('物理');
-- 插入教师数据
INSERT INTO teachers (name, department)
VALUES ('赵老师', '数学系'),
('钱老师', '英语系'),
('孙老师', '物理系');
-- 插入成绩数据
INSERT INTO grades (student_id, course_id, grade)
VALUES (1, 1, 85.5),
(1, 2, 78.0),
(2, 1, 90.0),
(2, 2, 88.5),
(3, 1, 75.0),
(3, 3, 80.0);
-- 插入授课数据
INSERT INTO teachings (teacher_id, course_id)
VALUES (1, 1),
(2, 2),
(3, 3);