Slawomir Nowaczyk wrote:
On Wed, 17 Aug 2005 17:27:17 -0500
Puneet Kishor <[EMAIL PROTECTED]> wrote:
#> Maintaining the integrity of state is important when modifying.
#> While reading, why would you want to read something that is
#> possibly stale.
I don't think "stale" is a good word.
SELECT amount as a1 FROM money WHERE name = me;
SELECT amount as a2 FROM money WHERE name = you;
Now, how much money do we have together? a1 + a2? Yes, but only if the
above statements were wrapped in a transaction... otherwise, somebody
might have executed "BEGIN; UPDATE amount = amount + 1000 WHERE name =
me; UPDATE amount = amount - 1000 WHERE name = you; COMMIT" in-between
those two selects.
Integrity can be important :)

I actually got your point the first time ;-). And I certainly don't want to make this into a long drawn out thread a la "are threads safe or not" ;-)

However, the very example above shows why integrity is important. Without the transaction, I will see exactly how much money you and I have at any given moment on doing a SELECT. With the transaction, the latest UPDATE will not be reflected unless it gets done before my SELECT transaction started. A transaction is important, just not on a statement that doesn't modify data, unless the application design specifically asks for consistent, but possibly stale (hence, possibly inaccurate) data.

On the other hand, a transaction for the UPDATE statements is definitely essential, else you will be richer by a 1000 and I will be poorer. Not good.


--
Puneet Kishor

Reply via email to