Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete row with a Mysql Trigger

Tags:

mysql

triggers

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 

So far My Trigger looks like this but has an error

-- Trigger DDL Statements
DELIMITER $$

USE `db_dhruniversity`$$

CREATE
TRIGGER `db_dhruniversity`.`ai_delete_course`
AFTER DELETE ON `jos_jquarks_quizzes`
FOR EACH ROW
BEGIN    
DELETE FROM jos_jquarks_courses
WHERE (quiz_id = new.id); 
END$$
like image 990
Tony77 Avatar asked Aug 26 '11 18:08

Tony77


1 Answers

In your where clause change new.id to old.id

-- Trigger DDL Statements
DELIMITER $$

USE `db_dhruniversity`$$

CREATE
TRIGGER `db_dhruniversity`.`ai_delete_course`
AFTER DELETE ON `jos_jquarks_quizzes`
FOR EACH ROW
BEGIN    
DELETE FROM jos_jquarks_courses
WHERE (quiz_id = old.id); 
END$$
like image 194
Ashwini Dhekane Avatar answered Sep 30 '22 14:09

Ashwini Dhekane