学生表
id|student_num|name|surname
课程表
id|course_name
Student_course表
course_id|student_id|mark
当我将数据插入学生表(id,student_num,name,surname)时,应将id插入Student_course Table,student_id列。
答案 0 :(得分:0)
假设您要为所有课程插入新学生,那么在Postgres中您可以这样做:
with new_student as (
insert into student
(id, student_num, name, surname)
values
(1, 42, 'Dent', 'Arthur)
returning id
)
insert into Student_course (student_id, course_id)
select (select id from new_student),
id
from course;