# My trigger doesn't work

**URL:** <https://forum.codewithmosh.com/t/my-trigger-doesnt-work/23544>\
**Category:** SQL\
**Created:** [November 10, 2023, 7:14am UTC](https://forum.codewithmosh.com/t/my-trigger-doesnt-work/23544 "2023-11-10T07:14:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Huang](https://avatars.discourse-cdn.com/v4/letter/h/8797f3/32.png) [@Huang](https://forum.codewithmosh.com/u/Huang)\
**Post date:** [November 10, 2023, 7:14am UTC](https://forum.codewithmosh.com/t/my-trigger-doesnt-work/23544/1 "2023-11-10T07:14:31Z")

</div>

I followed Mosh’s code at my machine for Trigger and Insert.  
I cannot find anything wrong from my scripts.

However, it just cannot work. Can anyone help?  
Here is my code:

DELIMITER $$

CREATE TRIGGER payments\_after\_insert  
AFTER INSERT ON payments   
FOR EACH ROW  
BEGIN  
UPDATE invoices  
SET payment\_total = payment\_total + NEW.amount  
WHERE invoice\_id = NEW.invoice\_id;  
END$$

DELIMITER ;

And the part for INSERT:  
INSERT INTO payments   
VALUES (DEFAULT, 5, 3, ‘2019-01-01’, 10, 1)

I execute the Trigger first and then the Insert part, but my invoices table just doesn’t update.  
Anything wrong at my code?

---

<div class="post-metadata">

**Author:** ![Huang](https://avatars.discourse-cdn.com/v4/letter/h/8797f3/32.png) [@Huang](https://forum.codewithmosh.com/u/Huang)\
**Post date:** [November 15, 2023, 2:53am UTC](https://forum.codewithmosh.com/t/my-trigger-doesnt-work/23544/2 "2023-11-15T02:53:08Z")

</div>

I changed the code as below and it finally works.

DELIMITER //

CREATE TRIGGER payments\_after\_insert  
AFTER INSERT ON payments   
FOR EACH ROW  
BEGIN  
UPDATE invoices  
SET payment\_total = payment\_total + NEW.amount  
WHERE invoice\_id = NEW.invoice\_id;  
END //

INSERT INTO payments   
VALUES (DEFAULT, 5, 3, ‘2019-01-01’, 10, 1)

Even though no one answers, I do hope this can help someone facing the same problem as me.

Wish you great.

---

<div class="post-metadata">

**Author:** ![doug\_gaming](https://avatars.discourse-cdn.com/v4/letter/d/ecae2f/32.png) [@doug\_gaming](https://forum.codewithmosh.com/u/doug_gaming)\
**Post date:** [February 10, 2024, 5:19pm UTC](https://forum.codewithmosh.com/t/my-trigger-doesnt-work/23544/3 "2024-02-10T17:19:16Z")

</div>

I still could not get to work with the above example either. When I executed SHOW TRIGGERS; it returned nothing so I researched further and looks like it has to do with access rights: [mysql - Triggers hidden - Database Administrators Stack Exchange](https://dba.stackexchange.com/questions/121863/triggers-hidden) But I tried  
USE sql\_invoicing;

GRANT TRIGGER ON payments to ‘root’@‘localhost’;  
which mySQL Workbench said was all fine and dandy, But SHOW TRIGGERS; returned nothing and my trigger did not fire. I also see there are access permissions at the schema level which had TRIGGER checked. I checked all the others and applied but still no dice. mySQL Workbench 8.0. I am wondering do I have to recreate the trigger once again? Hello? Anyone? Bueller?
