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 822047
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T02:44:32+00:00 2026-05-15T02:44:32+00:00

How can I create a SQLite Trigger to calculate running totals on the Actual

  • 0

How can I create a SQLite Trigger to calculate running totals on the “Actual” table? The following SQL code should update the AccountBalances table so that the Balance column counts from 1, 2, 3, … rowcount. However, the trigger only updates the 2nd row, even when I turned on recursive_triggers. The result below is row 1 = 1, row 2 = 2, and rows after that are null.

CREATE TEMP TABLE "AccountBalances" (
  "Id" INTEGER PRIMARY KEY, 
  "DateId" INT,
  "AccountId" INT,
  "AccountCurrAmount" REAL,
  "Balance" REAL);

INSERT INTO "AccountBalances" 
  (DateId, AccountId, AccountCurrAmount)
  SELECT DateId, AccountId, Sum(AccountCurrAmount) 
    FROM Actual 
GROUP BY DateId, AccountId 
ORDER BY AccountId, DateId;

CREATE TRIGGER UpdateAccountBalance AFTER UPDATE ON AccountBalances
BEGIN
 UPDATE AccountBalances 
    SET Balance = 1 + new.Balance 
  WHERE Id = new.Id + 1;
END;

PRAGMA recursive_triggers = 'on';

UPDATE AccountBalances 
   SET Balance = 1 
 WHERE Id = 1
  • 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-05-15T02:44:32+00:00Added an answer on May 15, 2026 at 2:44 am
    1. Please check the value of SQLITE_MAX_TRIGGER_DEPTH. Could it be set to 1 instead of default 1000?

    2. Please check your SQLite version. Before 3.6.18, recursive triggers were not supported.

    Please note that the following worked for me 100% OK

    drop table “AccountBalances”

    CREATE TEMP TABLE "AccountBalances" (
      "Id" INTEGER PRIMARY KEY, 
      "Balance" REAL);
    
    INSERT INTO "AccountBalances" values (1,0)
    INSERT INTO "AccountBalances" values (2,0);
    INSERT INTO "AccountBalances" values (3,0);
    INSERT INTO "AccountBalances" values (4,0);
    INSERT INTO "AccountBalances" values (5,0);
    INSERT INTO "AccountBalances" values (6,0);
    
    CREATE TRIGGER UpdateAccountBalance AFTER UPDATE ON AccountBalances
    BEGIN
     UPDATE AccountBalances 
        SET Balance = 1 + new.Balance 
      WHERE Id = new.Id + 1;
    END;
    
    PRAGMA recursive_triggers = 'on';
    
    UPDATE AccountBalances 
       SET Balance = 1 
     WHERE Id = 1
    
    select * from "AccountBalances";
    

    Resulted in:

    Id  Balance
    1   1
    2   2
    3   3
    4   4
    5   5
    6   6
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote the following code in SQLite : CREATE TABLE payments ( customerNumber REAL
How can I create a insert trigger in sqlite? I should check if the
Can SQLite sort naturally? For example, CREATE TABLE animals ( id INTEGER NOT NULL
Can I create in SQLite a statement like this? update books set (if number_of_pages
i can able to create table to my sqlite data base but i can't
Being newbie in SQL, can some help me adapt this trigger to either sqlite
Currently, I am using the following statement to create a table in an SQLite
I've been working on a system where you can create-read-update-delete to/from a table in
You can create a table model and add it to a table TableModel tm
i use the statement drop trigger if exist TRIGGER in sqlite but sql server

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.