Overview: In my scenario a user uploads an excel file that needs to be written into database, I am allocating each uploaded file a batch_id that batch_id is written in last column of each row of my table as shown in these pictures
With the help of this batch_id column I will be able to segregate that which rows belong to which document.(for example: if batch_id=1 than these 1000 rows belongs to document 1)
Problem: Consider two users user1 and user2 executing this stored procedure at the same time while Stored Procedure is writing batch_id=1 in all the rows which belong to document1,at the same time rows belonging to document2 will gets inserted thus causing a conflict wether to write batch_id=1 or batch_id=2 in the rest of remaining rows.
Imperfect Solution: To Execute Stored Procedure on one document at a time,when its done execute it on document 2 but this will let the user to wait until the current execution finishes which i don't want to happen.
UPDATE:::::::::::::::
The batch_id value is coming from another table MASTER_CDT in this table batch_id is primary key and auto incremented, when a document gets uploaded first a batch_id is generated this batch_id is then inserted into rows corresponding to that batch, the problem is while batch_id(consider batch_id=1) is getting written into current batch rows if another user uploads document then batch_id is changed to value 2 while rows regarding batch 1 are still missing batch_id value but now batch_id=2 will be written to them therefore causing trouble.