Database design: Calculating the Account Balance
        Posted  
        
            by 
                001
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by 001
        
        
        
        Published on 2010-12-07T06:28:14Z
        Indexed on 
            2010/12/27
            19:53 UTC
        
        
        Read the original article
        Hit count: 313
        
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.
© Stack Overflow or respective owner