Reputation: 327
I'm trying to log changes of a table into another table. But my trigger is not working. Need help:
// Mysql code below
create trigger upd_stu_info
before update
on kisalg_student
for each row
begin
IF OLD.stu_name != NEW.stu_name
THEN
INSERT INTO `kisalg_logactions`
(adm_no, change_type,change_head, old_value,new_value,user,date_time,session)
VALUES
(NEW.adm_no, 'stu_info','Change In Student Name ', OLD.stu_name, NEW.stu_name, NEW.user, NEW.date_time, NEW.session);
END IF;
IF OLD.fat_name != NEW.fat_name
THEN
INSERT INTO `kisalg_logactions`
(adm_no, change_type, change_head, old_value, new_value, user, date_time, session)
VALUES
(NEW.adm_no, 'stu_info','Change In Father Name ', OLD.fat_name, NEW.fat_name, NEW.user, NEW.date_time, NEW.session);
END IF;
end;
Upvotes: 0
Views: 132
Reputation: 44844
I just tried the trigger on mysql and using the following I did not get any syntax error
delimiter //
create trigger upd_stu_info
before update
on kisalg_student
for each row
begin
IF OLD.stu_name != NEW.stu_name
THEN
INSERT INTO `kisalg_logactions`
(adm_no, change_type,change_head, old_value,new_value,user,date_time,session)
VALUES
(NEW.adm_no, 'stu_info','Change In Student Name ', OLD.stu_name, NEW.stu_name, NEW.user, NEW.date_time, NEW.session);
END IF;
IF OLD.fat_name != NEW.fat_name
THEN
INSERT INTO `kisalg_logactions`
(adm_no, change_type, change_head, old_value, new_value, `user`, date_time, session)
VALUES
(NEW.adm_no, 'stu_info','Change In Father Name ', OLD.fat_name, NEW.fat_name, NEW.`user`, NEW.date_time, NEW.session);
END IF;
end; //
Upvotes: 1