I have built an accounting system, where in a SQL Table, two of the columns are : Amount and Balance Left in the following manner :
ID Amount Balance Left 101 20 100 102 20 80 103 10 70 104 30 40 105 25 15 106 5 10
Such that: Balance Left = previous Balance Left - Amount
.
Now if I delete a row with Id say 103, I would want amount 10 added to all the subsequent rows. What is the best possible way to do that (in SQL Server 2008 or otherwise)?
P.S. :
I'm aware that I can add a trigger to update each row, but looking for a better alternative, if any.
Code in C#.
In reply to some of the questions and common answers : 1. Considering there are a million rows below my deleted row - Would it be better to do it in C# via LINQ? or would a SQL trigger work faster? 2. I know its preposterous to save the balance left with each entry, but thats how the user of the DB/software demands it.