Geeks With Blogs
Stephanie Grima C#, ASP.NET and my life.


A customer has two bank accounts. In bank account A, he has 50 Euros. On bank account B, he has 100 Euros. The customer wants to put 25 Euros from bank account A in bank account B. In order to do this, one should have two SQL statements:

UPDATE AccountA SET Balance = Balance – 25 WHERE Customer = 1;
UPDATE AccountB SET Balance = Balance + 25 WHERE Customer = 1;

However, if the first update statement successfully executes, and the second one fails, the customer will end up with having 25 Euros deducted from account A and that's it. He will lose the 25 Euros forever.

Beause of this, Transactions were created. Thanks to transactions, one has the ability to only commit changes if all the SQL Commands executed successfully. And if they failed, one uses the rollback function to undo what has been done.

Posted on Monday, October 27, 2008 9:25 AM C# | Back to top

Comments on this post: Transactions [C#]

No comments posted yet.
Your comment:
 (will show your gravatar)

Copyright © Steffi | Powered by: