Imagine such a scene. For example, a test table has fields
count:0
name:'abc'
When the user opens an editing interface, the data read from the database is
count:3
name:'abc'
Then he changed his name and it became like this
count:3
name:'efg'
At this moment, other programs are reading and writing this test table at high speed. Because the user has not saved the data to the data table, the data saved by other programs is
count:40
name:'abc'
Continuously change the count field to 41, 42, 43. At this time, the user has completed the modification and saved the data to the database. The final data saved at this time is
count:3
name:'efg'
Then the problem arises. . . There is a problem with the count field data.
how to solve this problem?
1. Either separate the count field into another table, and then associate the two tables without interfering with each other. However, when reading data in this way, two tables need to be read, which is a bit troublesome.
2. When the user saves data, only the necessary fields are updated. For example, the count field reads the old one from the database. However, when the data table has dozens of fields, the procedure is a little cumbersome.
How did you solve it?
天蓬老师2017-06-05 11:14:48
Typical transaction issues.
What database are you using? Have you studied business? Learn how the database you use supports transactions.
To put it simply: lock the data so that only one client can perform read and write operations at the same time, and other clients have to wait.