3

I need trigger That Deletes row where in table paym both columns table1 and table2 are not empty.

Example in tables below: table: paym

 ID        username        table1        Table2  
+-------+-------------+-------------+-----------+
|   1   |  John       |  Value      |    Value  |
+-------+-------------+-------------+-----------+
|   2   |  Alex       |  Null       |    Null   |
+-------+-------------+-------------+-----------+

Condition is True: After Deleted row:

 ID        username        table1        Table2  
+-------+-------------+-------------+-----------+
|   2   |  Alex       |  Null       |    Null   |
+-------+-------------+-------------+-----------+

My attemp is: (Not working)

CREATE trigger DeleteROW
AFTER UPDATE ON paym
FOR EACH ROW
    BEGIN
        IF (NEW.table1 IS NOT NULL AND NEW.table2 IS NOT NULL) THEN
          DELETE
    FROM
        paym WHERE table1 and table2 IS NOT NULL ;
        END IF;
    END
2
  • 3
    I don't think you can do that in a before update or after update trigger. Commented Apr 10, 2019 at 18:42
  • 1
    @danb Any other ways? Commented Apr 10, 2019 at 19:13

1 Answer 1

2

A trigger cannot modify the table it is running on.

You should create a stored procedure to handle this, and call that instead of the DELETE command...

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

Comments

Your Answer

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