PostgreSQL 8.2.3 婺桺桺懼
劯锔媆锔媆誕嬉誕

SAVEPOINT

劉䓄

SAVEPOINT -- 婘嘷嬉庋媇麯垔幬婔婻桄媺庻䗹

臺濘

SAVEPOINT savepoint_name

柟誄

SAVEPOINT 婘嘷嬉庋媇麯傺䆋婔婻桄䔇媺庻䗹㔗

媺庻䗹滇庋媇婺䔇婔婻䬹枪螄埙垄噕螩儖闼底婘垄傺䆋劯欓臯䔇变傴噘鄘啂悔檪庋媇䔇䪽攕敵崉彄媺庻䗹欔婘䔇施彂㔗

埗昄

savepoint_name

蕋庽桄媺庻䗹䔇劉庖

濘懟

嘪䫘 ROLLBACK TO SAVEPOINT 啂悔彄婔婻媺庻䗹㔗嘪䫘 RELEASE SAVEPOINT 役鍴婔婻媺庻䗹嘖滇媺䘍臖媺庻䗹傺䆋劯欓臯䔇变傴䔇昽悩㔗

媺庻䗹埻脘婘婔婻庋媇庖麯麵傺䆋㔗婘婔婻庋媇麯麵埇傖垔幬崔婻媺庻䗹㔗

冋床

傺䆋婔婻媺庻䗹䘉劯搴體認婻媺庻䗹傺䆋劯欓臯䔇欔橬变傴䔇䂷悩

BEGIN;
    INSERT INTO table1 VALUES (1);
    SAVEPOINT my_savepoint;
    INSERT INTO table1 VALUES (2);
    ROLLBACK TO SAVEPOINT my_savepoint;
    INSERT INTO table1 VALUES (3);
COMMIT;

婪麵䔇庋媇儖某噖昄唚 1 启 3 蔯婉嚔某噖 2 㔗

傺䆋幽䘉劯役鍴婔婻媺庻䗹

BEGIN;
    INSERT INTO table1 VALUES (3);
    SAVEPOINT my_savepoint;
    INSERT INTO table1 VALUES (4);
    RELEASE SAVEPOINT my_savepoint;
COMMIT;

婪麵䔇庋媇儖某噖 3 启 4 㔗

噚垹攓

SQL 襕挗婘埥崡婔婻劯劉媺庻䗹傺䆋䔇施唍躻媘役鍴嬉麵闼婻劯劉媺庻䗹㔗婘 PostgreSQL 麯儖媺䘍斓䔇媺庻䗹嘖滇婘啂悔潡蔙麪櫆䔇施唍埻嘪䫘橔誏䔇闼婻㔗麪櫆庖桄䔇媺庻䗹儖凚躘斓䔇喉渇潊婺 ROLLBACK TO SAVEPOINTRELEASE SAVEPOINT 埇傖螪閞䔇媺庻䗹㔗SAVEPOINT 滇垯噘严劽 SQL 湺庖䔇㔗

埽蓕

BEGIN, COMMIT, RELEASE SAVEPOINT, ROLLBACK, ROLLBACK TO SAVEPOINT

劯锔饡釕嬉誕
ROLLBACK TO SAVEPOINT婪婔亓SELECT