Wednesday, 21 August 2013

Insert entry into junction table connected tables in one INSERT opertion

Insert entry into junction table connected tables in one INSERT opertion

There are 3 tables. I use mysql. students can enroll in many course(many
to many)
CREATE TABLE `classes`
(
`name` VARCHAR(20),
`class_id` VARCHAR(20)
);
CREATE TABLE `students`
(
`name` VARCHAR(20),
`student_id` INT(11)
);
CREATE TABLE `studentsclasses`
(
`class_id` VARCHAR(20),
`student_id` INT(11)
);
Date in table "classes" is populated before students table is. Is it
possible to have one single insert instruction that can insert data into
"student" table and "studentsclasses" at the same time? Google suggest
that the work around is to have two insert operations at application front
end, but is there a better way to do this(like trigger) which requiring
less programming on front end application?
Edit: more specific

No comments:

Post a Comment