假設我要執行三條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 回答
已采納

LIANHK
TA貢獻78條經驗 獲得超17個贊
折返點
SAVEPOINT adqoo_1
ROLLBACK TO SAVEPOINT adqoo_1
發生在折返點 adqoo_1 之前的事務被提交,之后的被忽略
可以每一條執行后都 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貢獻100條經驗 獲得超24個贊
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;
添加回答
舉報
0/150
提交
取消