title: concurrency Control for inserting records based on previous transaction
body: <p>I am having a situation in which i have to make the entries from TableA to TableB such that i need to counter-balance the entries.
  For example: 
  TableA
  ID    Name
  1   A
  2   B
  3   C
  if no entries in TableB of Table for any user,i will add entries in 
  TableA for User1 As</p>
  
  <pre><code>ID  TableA_ID   UserID
  1       1       1
  2       2       1   
  3       3       1
  </code></pre>
  
  <p>For anther user say User2, i need to check for the entries of lastUser and find out which entry made first. Entry which made first will be made at last for next user. As</p>
  
  <pre><code>ID    TableA_ID   UserID
  1         1         1
  2         2         1   
  3         3         1
  4         2         2
  5         3         2   
  6         1         2
  </code></pre>
  
  <p>Similiar for next user enteries will be </p>
  
  <pre><code>7         3         3
  8         1         3   
  9         2         3
  </code></pre>
  
  <p>Problem here is that all users may request at the same time and i need to implement locking mechanism to handle it. For any user's request, i need to find the entries for last user. The table must be locked until user makes entries in tableB. In Short i want to control the concurrency. Please suggest how to implement it. It would be better if it does not effect the entries from TableC to TableB.</p>