在线
客服

发布
需求

在线
聊天

天盟
APP

天盟APP下载

关注
微信

微信扫一扫访问
顶部

关于mysql事务的问题

假设我要执行三条sql语句 :

insert into user1 ( id , name , pwd ) values( null , 111 , 111 ) ;
insert into user2 ( id , name , pwd ) values( null , 222 , 222 ) ;
insert into user3 ( id , name , pwd ) values( null , 333 , 333 ) ;
当第二条执行失败时 , 撤销第一条的提交 . 当第三条执行失败时 , 撤销第二条的提交 , 同时让第一条提交 :
这事务怎么写 ?

免责声明:本内容仅代表回答会员见解不代表天盟观点,请谨慎对待。

版权声明:作者保留权利,不代表天盟立场。

使用道具 举报

全部参与2

折返点
SAVEPOINT adqoo_1
ROLLBACK TO SAVEPOINT adqoo_1
发生在折返点 adqoo_1 之前的事务被提交,之后的被忽略


可以每一条执行后都 SAVEPOINT

--第一步:insertintouser1(id,name,pwd)values(null,111,111);SAVEPOINTpoint_1;--第二步:insertintouser2(id,name,pwd)values(null,222,222);SAVEPOINTpoint_2;--第三步:insertintouser3(id,name,pwd)values(null,333,333);SAVEPOINTpoint_3;然后哪一步失败就 ROLLBACK TO SAVEPOINT XXX
如第二步失败:
ROLLBACKTOSAVEPOINTpoint_1;望采纳

使用道具 举报

begin;insertintouser1(id,name,pwd)values(null,111,111);insertintouser2(id,name,pwd)values(null,222,222);insertintouser3(id,name,pwd)values(null,333,333);end;

使用道具 举报

发新帖
国内首家创新型IT技术需求众包服务平台,软件需求就上天盟网! 立即登录 立即注册