use sandbox;

drop table if exists sandbox;

create table sandbox(
  primary_key int unsigned auto_increment primary key,
  ch char(1)
);

drop table if exists sandbox_status;

create table sandbox_status(
  primary_key int unsigned auto_increment primary key,
  status smallint(5) unsigned default 0
);


drop procedure if exists Sandbox;

delimiter //

create procedure Sandbox ()
  comment "sandbox procedure"

Sandbox: begin
  declare var1_before int;
  declare var1_after int;
  declare var2_before int;
  declare var2_after int;

  start transaction;

  select last_insert_id() into var1_before;
  insert into sandbox(ch) values ("a");
  select last_insert_id() into var1_after;

  if var1_after > var1_before then
    select last_insert_id() into var2_before;
    insert into sandbox_status(status) values (1);
    select last_insert_id() into var2_after;
  end if;

  select var1_before, var1_after;
  select var2_before, var2_after;
 
  commit;
end Sandbox;
//

delimiter ;
