title: mysql concurrency
body: <p>sorry if my question has been asked before or if it's too obvious but i really need to clear this. thanks for your help.</p>
  
  <p>in a multi-user interface, if the same transaccion from different users arrive to server at the same time, what will happen? </p>
  
  <p>i have the next table:</p>
  
  <pre><code>create table table_x (
    cod char(2) not null,
    desc varchar(45) not null,
    primary key (cod)
  );
  </code></pre>
  
  <p>where these calls arrive at the same time to the server:</p>
  
  <pre><code>call sp_s('1','a');
  call sp_s('1','b');
  call sp_s('1','c');
  </code></pre>
  
  <p>what sp_s (in param_a char(2), in param_b varchar(45)) does is:</p>
  
  <pre><code>declare var_count tinyint default 0;
  
  set var_count=
  (select count(*) 
  from table_x 
  where cod=param_a);
  
  if(var_count=0) then
  insert into table_x values (param_a, param_b);
  else
  update table_x set desc=param_b
  where cod=param_a;
  end if;
  </code></pre>
  
  <p>if the registry doesn't exists it inserts it, but if it exists the sp updates it.</p>
  
  <p>is this a good way to do it without using autoincrement?
  whats the best way to avoid concurrency if i'm not using auto_increment?</p>
  
  <p>thanks very much for your time.</p>