假設(shè)我要執(zhí)行三條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 ) ;當(dāng)?shù)诙l執(zhí)行失敗時(shí) , 撤銷第一條的提交 . 當(dāng)?shù)谌龡l執(zhí)行失敗時(shí) , 撤銷第二條的提交 , 同時(shí)讓第一條提交 :這事務(wù)怎么寫 ?
2 回答
已采納

LIANHK
TA貢獻(xiàn)78條經(jīng)驗(yàn) 獲得超17個(gè)贊
折返點(diǎn)
SAVEPOINT adqoo_1
ROLLBACK TO SAVEPOINT adqoo_1
發(fā)生在折返點(diǎn) adqoo_1 之前的事務(wù)被提交,之后的被忽略
可以每一條執(zhí)行后都 SAVEPOINT
--?第一步: insert?into?user1?(?id?,?name?,?pwd?)?values(?null?,?111?,?111?); SAVEPOINT?point_1; --?第二步: insert?into?user2?(?id?,?name?,?pwd?)?values(?null?,?222?,?222?); SAVEPOINT?point_2; --?第三步: insert?into?user3?(?id?,?name?,?pwd?)?values(?null?,?333?,?333?); SAVEPOINT?point_3;
然后哪一步失敗就 ROLLBACK TO SAVEPOINT XXX
如第二步失?。?/p>
ROLLBACK?TO?SAVEPOINT?point_1;
望采納

人笨嫌刀鈍
TA貢獻(xiàn)100條經(jīng)驗(yàn) 獲得超24個(gè)贊
begin; 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?)?; end;
添加回答
舉報(bào)
0/150
提交
取消