现在的位置: 首页 > 综合 > 正文

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

2017年11月24日 ⁄ 综合 ⁄ 共 466字 ⁄ 字号 评论关闭

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();

抱歉!评论已关闭.