views:

19

answers:

1

This is just for my own understanding of how concurrency issues work. Let's say I have an insert statement that runs at the same time as a select query. If the insert statement occurs while the select query is still running, will the select query show a conflict because the number of rows to select has changed?

Or is it that concurrency conflicts can only arise when rows are edited, making insert statements completely harmless (in terms of concurrency conflicts)?

A: 

The wikipeida article for this is pretty decent:

Concurrency Control

But basically concurrency issues happen anytime data that a transaction is using is changed by another transaction.

So Lets say I get the top 100 rows from the database. Someone else makes a change to row 5. Then I try to change row 5 based on my read of it.

Or an insert case.

Let's say that I pull all the children at a school, and want to figure out how many have names starting with A. Then someone adds 10 more children starting with A. That's a concurrency issue.

You can have bad things happen from an insert that causes something to happen that you weren't expecting to be in the database.

For example:

John has a balance owed of $1000, he comes online to pay his bill, during that time a transaction happens that causes him to owe another $100 (insert) (total $1100). He pays his $1000 in full which triggers something to set all of his owed balances to 0 (He paid all the ones that we got so we say ahh let's just set everything to 0). That $100 transaction is now cleared without it actually being paid.

msarchet