views:

79

answers:

1

Hi all, I need help in how to transfer data from one account no to another account no in single table. In this customer will get his account no from dropdown list(it will come automitically thru his session) and customer has to write the destination account no in textbox and the amount he is transferring will be written in another textbox.Before transferring the amount, destination account no and the balance amount should be validated.

Customer_Account table:

AccountId      UserId  Status   Balance   AccountCode
101            xyz      A        2000     SB ->Savings
102            abc      A        3000     SV->Current
103            yxz      A        4000     SI->Joint

For SB MinBalance 500,SV 1000,SI 2000 should have

Transaction Table:

TransactionID, AccountID, TransactionType, Amount, DOT, UserID ,SourceOrDestAccountId ,TransferFlag,Balance

In this If AccountId 101 want to transfer his 1000 amount to AccountId 102 AccountId 101 will be debited and AccountId 102 will be credited.

Please somebody help me in coding, this problem.

Thanks, Masum

A: 

Check your text book(s) for "transactions" and see how to explicitly begin a transaction. Once you know how to wrap a series of statements within a transaction it's just a matter of performing all of the necessary checks and rolling back if there's a problem.

Although most banks allow negative balances, I'm going to guess that for your homework this isn't the case - if they don't have enough funds to transfer it should fail. If that's true then a constraint on the Amount column could be useful. Then you don't need to explicitly check it. If you want to allow for negative balances then I would probably code something like this: (pseudo-code. I wouldn't try to hand this in. You'll need to do some work yourself if you want to learn.):

Start a transaction

Update the source account to decrement the amount by the amount being transferred

Check to see if the Amount on the source account is less than 0. If it is, rollback the transaction

Update the destination account to increment the amount by the amount being transferred

Commit the transaction

Also include any other error checking that you think is appropriate. How you do this will be dependent on your particular database.

Tom H.
Hi this is not a home work......for your understanding i have given simple example.
It probably shouldn't be tagged as homework then. What RDBMS are you using?
Tom H.
I think we're using "transaction" in two different contexts. The OP is using the word in the banking sense. Tom's response is using it in the database sense. I believe the solution the OP is looking for is what values would go into the Transaction table to model the action of transferring money from one account to another.
Barry Brown