简体   繁体   中英

Allow multiple users to update same record

I have a situation where there is one record in database table ie 'abcde'. And User 'X','Y' and "Z' tries to update that record at the same time.

'X' modify abcde to abcdd

'Y' modify abcde to abddd

'Z' modify abcde to abeee

All changes should persist in database table.

Is it possible than please provide the solution.

If you want to persist all changes, then you will need at least one more database table that keeps track of all these changes...a log/history table. The question is, how do you want to handle concurrency? If you don't care about it and you only want to keep the last modification in this single record table, then you don't need any further action, except the "logging" functionality that keeps track of all changes. But, if you do care about concurrency and want to handle it in a different then you should look at running transactions with the isolation level that best suits your needs

As you want to log the updated records only for the concurrent case . Have a column of DateTime in the table and when you display the record to keep the track of datetime. So here is the use case.

First User updated the record -> Update the original record withchange in DateTime column value also.

When Second User try to update you found that datetime has been changed , it means it is no more Update , it will be an inset statement.

It will be similar case of 2 for third user.

Now you are left with all the three records in the database.Remember in this case Primary key need to have some incremented column also otherwise it will throw an error.

You can use Trigger and save records in another Table for every operation. Capture data Change(CDC) will also work in your situation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM