I'm working with an application that adds a new row to the database, based on the last row meeting a certain criteria. Is there a standard pattern for dealing with this type of problem, or do I simply need to lock the table?
Here is an over-simplified visualization:
A1
A2
A3
B1
B2
Using the visualization above, a web page loads up the highest "B" value, which is "2". Then, after some time, it wants to insert B3, the next record in the series. However, it has to check to make sure that someone else didn't do the same thing.
Like I mentioned, I know that I can read the expected value within a transaction, or I could lock the table, or possibly even the last row. What I'm asking is if there is what the recommended strategy is.