Use of lock and unlock operations in concurrent transaction?

1 answer

Answer

1096576

2026-07-18 16:20

+ Follow

If you lock a row in a database you maintain data integrity. If two sources attempt to update the same record at the same time you could run into concurrency issues.

The database momentarily locks a record when you are updating it on its own.

To specifically lock a record, and subsequently unlock the record gives you more control. This is load bearing on the database and typically you do not want to do this.

One such case that this makes sense would be in the following situation:

If you need to update a row and that update is based on calculation that you will make; based upon information presently in that record and other associated records / tables, AND this calculation may take a few seconds (rather than instant); THEN you will want to lock the associated records, perform your calculations; update the data and then release the lock.

This insures that no changes will occur to the data, that your calculations are relying on, while you are performing your task.

ReportLike(0ShareFavorite

Copyright © 2026 eLLeNow.com All Rights Reserved.