title: Adding max(value)+1 in new row, can this be a problem?
body: <p>In a SQL Server table I have the following 2 columns:</p>
  
  <p><strong>RowId</strong>: primary key, numaric, identity column and auto insert.<br>
  <strong>MailId</strong>: Non key, numaric, non identity and non auto insert.</p>
  
  <p>Mail Id can be duplicate. In case of new MailId I will check max(MailId)+1 and insert it in new row and in case of duplication value will be coming as parameter.</p>
  
  <p>Logic looks fine but here is an issue, I was just considering (yet chacnes of accurance are ver low) In the same time there can be two different new MailId requests. Can this casue logical error ? For example when code checked max(MailId)+1 was 101 and I stored it in a variable but may be before next insert statment executs a new record inserted in table. Now max(MailId)+1 in table will be 102 but value in variable will be 101 ?</p>
  
  <p>Any suggestion please I want to control this error chances as well.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>(I am not using identity(1,1) because I also have to pass custom values in it)</p>