Reputation:
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
Upvotes: 3
Views: 194
Reputation: 6289
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...
Upvotes: 2