U
U
uuuu2020-05-30 23:38:36
MySQL
uuuu, 2020-05-30 23:38:36

How to delete in MySQL triggers?

Cannot delete rows whose count data is less than or equal to 0. When updating a row, it throws error 1442.

CREATE TRIGGER `tr1` AFTER UPDATE ON `test`
FOR EACH ROW 
BEGIN
DELETE FROM `test` WHERE `count`<=0;
END;

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
bkosun, 2020-05-31
@uuuu

No, it's impossible. You cannot make edits in the table for which the trigger is created (except for editing the current row):

In general, you cannot modify a table and select from the same table in a subquery.

https://dev.mysql.com/doc/refman/8.0/en/subquery-r...
https://bugs.mysql.com/bug.php?id=17549
Use an event scheduler if an action needs to be performed on the MySQL side

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question