M
M
mr_creo2017-05-10 22:10:51
MySQL
mr_creo, 2017-05-10 22:10:51

How to pull the trigger?

There is a table in which one of the columns is defined as unique. When inserting a duplicate value, you need to catch the primary key and throw the table into the log. I think it is necessary to cause the trigger, function or procedure. I tried to insert via INSERT INTO ... ON DUPLICATION KEY UPDATE `id` = `id` on the table, I hung the AFTER UPDATE trigger, but when updating the id itself, it looks like the update is cut during optimization and is not performed at all, therefore the trigger does not work.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2017-05-10
@Rsa97

Either BEFORE UPDATE, but the trigger will have to check the uniqueness of the added value.
Or add another column like `errors` and do ON DUPLICATE KEY UPDATE `errors` = `errors`+1. Then in the AFTER UPDATE trigger you can simply check for OLD.`errors` != NEW.`errors`.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question