2

I've written something like this and this is not working. How?

mysql> create trigger deleteStudentTrigger
-> before delete on tblStudent for each row
-> begin
-> insert into tblDeletedStudents select * from tblStudent where StudentId = new.StudentId;
-> end;$

ERROR 1363 (HY000): There is no NEW row in on DELETE trigger

2
  • The error message says it all! Commented May 8, 2017 at 7:11
  • Yeah, I know. I posted that to tell what I tried. Commented May 8, 2017 at 8:29

1 Answer 1

3

As stated in the error, there is no NEW row, only OLD (because when you delete something, it's not new you know) So it should be

mysql> create trigger deleteStudentTrigger
-> before delete on tblStudent for each row
-> begin
-> insert into tblDeletedStudents select * from tblStudent where StudentId = old.StudentId;
-> end;$

For more info refer to MySQL documentation

Sign up to request clarification or add additional context in comments.

3 Comments

No error. But INSERT operation to tblDeletedStudents not happening.
Shouldn't it be insert into tblDeletedStudents values (old.StudentId, old.anothercolumn, ...)?
insert select... is also possible. Well in your case I would test separately if the insert itself is ok (meaning table schema is the same for both tables)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.