I'm currently developing a website and while working on database design, i had some concern on concurrency issue, I'm considering using timestamping to avoid this.
My understanding in timestamping is that it works this way:
- There is a field for let's say "DateModified" wherein be updated every update on that specific row.
- Then whenever there are 1 or more users accessing that row like reading first then eventually update it.
- In my understaning of timestamping for this to work, I need a condition that will read first the "DateModified" like in my code.
readdatemodified = Select DateModified From Transaction where ID = ?
datemodified = Select DateModified From Transaction where ID = ?
IF datemodified == readdatemodified UPDATE Transaction where ID = ? ELSE Message "There's someone updated the record. Please try again".
IF: UPDATE the record successfully
ELSE: Here the record will be retrieve again by accessing the database to ensure that the record is the updated one.
I solved the concurrency issue here but my new concern is how I access the database. I will accessed the database multiple times every update?
Is there a way wherein I could minimize the database access using timestamping?