Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR SQL

pgsql commit rollback example

-- start a transaction
BEGIN;

-- deduct 1000 from account 1
UPDATE accounts 
SET balance = balance - 1000
WHERE id = 1;

-- add 1000 to account 2
UPDATE accounts
SET balance = balance + 1000
WHERE id = 2; 

-- select the data from accounts
SELECT id, name, balance
FROM accounts;

-- commit the transaction
COMMIT;
 
PREVIOUS NEXT
Tagged: #pgsql #commit #rollback
ADD COMMENT
Topic
Name
9+3 =