首页 > 代码库 > Mysql-事务

Mysql-事务

delimiter \create PROCEDURE p1(
    OUT p_return_code tinyint
)
BEGIN 
  DECLARE exit handler for sqlexception 
  BEGIN 
    -- ERROR 
    set p_return_code = 1; 
    rollback; 
  END; 
 
  DECLARE exit handler for sqlwarning 
  BEGIN 
    -- WARNING 
    set p_return_code = 2; 
    rollback; 
  END; 
 
  START TRANSACTION; 
    DELETE from tb1;
    insert into tb2(name)values(‘seven‘);
  COMMIT; 
 
  -- SUCCESS 
  set p_return_code = 0; 
 
  END\delimiter ;


set @i =0;
call p1(@i);
select @i;

  

Mysql-事务