Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9205941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:04:28+00:00 2026-06-18T00:04:28+00:00

MySql trigger is very interesting, but very tricky. I have some problem, I want

  • 0

MySql trigger is very interesting, but very tricky.

I have some problem, I want to run a trigger once after insert on .
I want to run my trigger once after rows inserted, is there anything like for each table“???

how to make this trigger run only once, but not for each row created.

CREATE
DEFINER=`root`@`localhost`
TRIGGER `mydb`.`leave_taken_trigger`
AFTER INSERT ON `mydb`.`leave`
FOR EACH ROW
BEGIN
    set @lt:= (SELECT count(*) FROM `leave` where  (staff_leave_application_staff_id_staff = new.staff_leave_application_staff_id_staff and leave_type_id_leave_type = new.leave_type_id_leave_type) and active = 1 );

        INSERT INTO `leave_taken`(leave_type_id_leave_type, staff_id_staff, taken_days, updated) 
        VALUES (new.leave_type_id_leave_type, new.staff_leave_application_staff_id_staff, IFNULL(@lt,0), CURDATE())
        ON DUPLICATE KEY UPDATE taken_days=IFNULL(@lt,0), updated = CURDATE(); 

END$$
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T00:04:29+00:00Added an answer on June 18, 2026 at 12:04 am

    I think you can’t achieve your requirement with trigger.
    Your trigger will run in every row created.
    I suggest you to using stored procedure from your code after the INSERT has successfully completed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a MySql database with just over 30 Million rows, but some of
I have problem with creating a simple MySQL trigger in C#. I'm using StringBuilder
Possible Duplicate: mysql getting last_insert_id() in a trigger I have MySQL TRIGGER firing AFTER
I have a very simple trigger. I cretaed it from Toad for mysql tool
I want to have a select statement inside the mysql trigger that has the
I have created an update trigger in MySQL Community Server 5.5.16 but when I
Starting with a MySQL trigger like this: delimiter # create trigger comments_after_ins_trig after insert
I have trouble defining a trigger for a MySQL database. I want to change
I have within my Sql Server 2008 database a trigger which will run on
My problem is very simple to explain but I don't success to find the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.