How should I write a simple bank schema?

How should I write a simple bank schema?

I am writing the schema for a simple bank database. Here are the basic specifications: The database will store transactions against a user and currency. Every user has one balance per currency, so each balance is simply the sum of all transactions against a given user and currency. A balance cannot be negative.

How to calculate account balance in a database?

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????

How to create a database for a bank?

Phase I: 1 Create a database for a banking application called “Bank”. 2 Create all the tables mentioned in the database diagram. 3 Create all the constraints based on the database diagram. 4 Insert at least 5 rows in each table. More

How to create ER diagram for Bank database?

1) The identifying relationship between the owner entity set, Bank, and the weak entity set, Bank_Branch must be one too many and Bank_Branch could only have one Bank as its owner. 2) The weak entity set, Bank_Branch, must have total participation in the identifying relationship set, BRANCHES.

How to keep balances in sync in SQL Server?

Have a separate balances table and do one of the following: Apply transactions to both the transactions and balances tables. Use TRANSACTION logic in my stored procedure layer to ensure that balances and transactions are always in sync.

How to get the current balance in SQL?

— Example of getting the current balance and locking the — last record for that User/Currency. — This lock will be freed after the Stored Procedure completes. SELECT TOP 1 @OldBalance = OpeningBalance + TransactionAmount FROM dbo.Transaction with (rowlock, xlock) WHERE UserID = 3 and CurrencyID = 1 ORDER By TransactionDate DESC;