本文共 844 字,大约阅读时间需要 2 分钟。
Transactions
Transactions are a fundamental concept of all database system. The essential point of a transaction is that it bundles multiple steps into a single, all-or-nothing operation. The intermediate states between the steps are not visible to other concurrent transaction, and if some failure occurs that prevents the transaction from completing, the none of the steps affect the database at all.In PostgreSQL, a transaction is set up by surrounding the SQL commands of the transaction with begin and commit commands.
BEGIN;UPDATE accounts SET balance = balance - 100.00 WHERE name = 'Alice';SAVEPOINT my_savepoint;UPDATE accounts SET balance = balance + 100.00 WHERE name = 'Bob';-- oops ... forget that and use Wally's accountROLLBACK TO my_savepoint;UPDATE accounts SET balance = balance + 100.00 WHERE name = 'Wally';COMMIT;
转载地址:http://zeyvb.baihongyu.com/