As a database developer, I'm having trouble with a problem of concurrency control while updating a

in a relational database.
Consider the following code where I try to update the salary of an employee with id 123:
Code:
BEGIN TRANSACTION;
UPDATE employees SET salary = salary + 1000 WHERE id = 123;
COMMIT;
However, this code can result in a race condition, where two transactions execute the same code at the same time, leading to lost updates. For example, if two transactions execute the code simultaneously, the final salary of the employee may not be what I expect. Here's an example of what can happen:
Transaction 1:
BEGIN TRANSACTION;
Code:
UPDATE employees SET salary = salary + 1000 WHERE id = 123;
//At this point, Transaction 1 has not yet committed.
Transaction 2:
Code:
BEGIN TRANSACTION;
UPDATE employees SET salary = salary + 1000 WHERE id = 123;
COMMIT;
Transaction 1:
In this scenario, the final salary of the employee will only be updated by Transaction 2 and the update made by Transaction 1 will be lost. This can lead to inconsistencies in the data and incorrect results in any reports or queries that rely on this data. To avoid this problem, I need to implement a proper concurrency control mechanism, such as pessimistic or optimistic locking, to ensure that only one transaction can update the tuple at a time.