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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T11:41:15+00:00 2026-05-18T11:41:15+00:00

How do I design the database to calculate the account balance? 1) Currently I

  • 0

How do I design the database to calculate the account balance?

1) Currently I calculate the account balance from the transaction table
In my transaction table I have “description” and “amount” etc..

I would then add up all “amount” values and that would work out the user’s account balance.


I showed this to my friend and he said that is not a good solution, when my database grows its going to slow down???? He said I should create separate table to store the calculated account balance. If did this, I will have to maintain two tables, and its risky, the account balance table could go out of sync.

Any suggestion?

EDIT: OPTION 2: should I add an extra column to my transaction tables “Balance”.
now I do not need to go through many rows of data to perform my calculation.

Example
John buys $100 credit, he debt $60, he then adds $200 credit.

Amount $100, Balance $100.

Amount -$60, Balance $40.

Amount $200, Balance $240.

  • 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-18T11:41:16+00:00Added an answer on May 18, 2026 at 11:41 am

    An age-old problem that has never been elegantly resolved.

    All the banking packages I’ve worked with store the balance with the account entity. Calculating it on the fly from movement history is unthinkable.

    The right way is:

    • The movement table has an ‘opening
      balance’ transaction for each and every account. You’ll need
      this in a few year’s time when you
      need to move old movements out of the
      active movement table to a history
      table.
    • The account entity has a balance
      field
    • There is a trigger on the movement
      table which updates the account
      balances for the credited and debited accounts. Obviously, it has commitment
      control. If you can’t have a trigger, then there needs to be a unique module which writes movements under commitment control
    • You have a ‘safety net’ program you
      can run offline, which re-calculates
      all the balances and displays (and
      optionally corrects) erroneous
      balances. This is very useful for
      testing.

    Some systems store all movements as positive numbers, and express the credit/debit by inverting the from/to fields or with a flag. Personally, I prefer a credit field, a debit field and a signed amount, this makes reversals much easier to follow.

    Notice that these methods applies both to cash and securities.

    Securities transactions can be much trickier, especially for corporate actions, you will need to accommodate a single transaction that updates one or more buyer and seller cash balances, their security position balances and possibly the broker/depository.

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

Sidebar

Related Questions

I have the following database design: Employee Table: Username, Name, DivisionCode Division Table: SapCode,
I have the following database design: Employee Table: Username, Name Quiz Table: QuizID, Title,
Possible duplicate: Database design: Calculating the Account Balance I work with a web app
For you database design/performance gurus out there. If you have a database that is
I have to design a database to handle forms. Basically, a form needs to
I have to design a database which will allow me store data in multiple
I want to design a database to store crossword puzzles, mainly I have 2
What's the best database design for the following problem: I have a product with
In database design what do n:m and 1:n mean? Does it have anything to
I'm building a Wine review site and have run into a database design problem

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.