skip to Main Content

I am using MySQL and I would like a field in my table to be periodically incremented per month. I’m making a banking application and would like to give an interest rate for all the accounts… can anyone please advice me on how to get started or go about doing it?… thank you

2

Answers


  1. You can use mysql scheduler to run it each month. You can find samples at
    http://dev.mysql.com/doc/refman/5.1/en/create-event.html

    Login or Signup to reply.
  2. First, ensure your table has a field to store the interest rate for each account.

    Next, define a scheduled event using MySQL’s CREATE EVENT statement. This event will execute periodically to increment the interest rate field for all accounts. You can specify the interval at which the event should run, such as every month.

    Within the event, write a SQL query to update the interest rate field for all accounts. This query should calculate the new interest rate based on the current rate and any applicable rules or formulas.

    Enable the MySQL event scheduler if it’s not already enabled. You can do this by setting the event_scheduler variable to ON.

    CREATE EVENT update_interest_rate
    ON SCHEDULE
        EVERY 1 MONTH
    STARTS CURRENT_TIMESTAMP
    DO
        UPDATE accounts
        SET interest_rate = interest_rate * (1 + monthly_interest_rate);
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search