MySQL开启事务的sql块的写法!

DELIMITER $$
use test$$
drop procedure if exists test.t1$$
use `test` $$
create procedure test.t1()
begin

    drop table if exists t1;
    create table test.t1 (c1 int)
    ENGINE = InnoDB;
   

      -- set autocommit=0; 这里设置为手动提交,或者下面开启事务,在这种情况下 rollback都有效。
    START TRANSACTION;
    insert into test.t1 select 1;
    select * from test.t1;
    rollback;
    select 2,c1 from test.t1;
    insert into test.t1 select 2;
    commit;
    select 3,c1 from test.t1;
    insert into test.t1 select 3;
    select 4,c1 from test.t1;

end

 

-- 测试

call test.t1();

你可能感兴趣的:(MySQL,开发)