I have a procedure which does two things
1) selects a field from the table1 get the value of a desired column
updates it by one and
2) updates the new incremented value back into that table.
Now when two users calling the procedure at same time then they both get the same value.
For e.g
if the value present in DB is 100
and two users call the procedure then ideally they should get 101 and 102.
but some time they are getting 101 for both.
Please help me in rectifying this error.
The procedure is :
DELIMITER $$
BEGIN
declare trc_id INT;
SELECT distinct column1 into trc_id FROM table1 where column2=match_name and status='A';
set abc=trc_id+1;
update table1 set column1=str_id where column2=match_name and column1=trc_id;
END $$
DELIMITER ;
Use Synchronized Method to your procedure.