I need to do trigger after Inserting on a table开发者_如何学运维 called jos_jquarks_quizzes, I need to create a course name which will have the same name as the quizz name , but its own id,
Tables
jos_jquarks_quizzes
id
title
description
course_id
jos_jquarks_users_training
id
quiz_id
user_id
agree
current approach
BEGIN
INSERT INTO jos_users_trainings
(jos_users_trainings.quiz_id) VALUES
SELECT jos_jquarks_quizzes.id FROM jos_jquarks_quizzes
END
Can you please help. Thanks in Advance
DELIMITER $$
CREATE TRIGGER ai_jos_jquarks_quizzes_each AFTER INSERT ON jos_jquarks_quizzes
FOR EACH ROW
BEGIN
INSERT INTO jos_users_trainings
(quiz_id) VALUES (new.id);
END $$
DELIMITER ;
In a trigger the virtual table new
holds the newly inserted values.
In an update
or delete
trigger the virtual table old
holds the values before the change.
精彩评论