0

In MySQL server, I want to do a trigger that checks when a row inserted, if the row has the previous value in column A than the previous row, it should delete it.

Im a little forgetful on how to check this correctly so if someone could lend a hand, thank you.

2
Contributors
4
Replies
10
Views
3 Years
Discussion Span
Last Post by riahc3
0

Best I got:

USE database;
DELIMITER $$
CREATE TRIGGER checkrow BEFORE INSERT ON table6 FOR EACH ROW
if inserted.column1 == select column1 from table6 order by id desc limit 1 then
delete inserted.column1

But after that...no clue what to do.

0

USE database;
DELIMITER $$
CREATE TRIGGER checkrow BEFORE INSERT ON table6 FOR EACH ROW
if inserted.sha1(column1) == select sha1(column1) from table6 order by id desc limit 1 then
delete inserted.column1;
end if

0

I don't think you can delete the record to be inserted. There must be a way to cancel it, perhaps by throwing an exception (signal).

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.