Created
January 8, 2013 21:32
-
-
Save emersoncortez/4488173 to your computer and use it in GitHub Desktop.
Transacciones con PostgreSQL - ROLLBACK.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- La cuenta A será cargada (se le quitará) y | |
-- la cuenta B será abonada (se le sumará) | |
-- Inicio de la transacción | |
BEGIN; | |
-- Cargando la cuenta A. | |
UPDATE cuentas SET saldo_cuenta = saldo_cuenta - monto WHERE nombre_cuenta = 'A'; | |
-- Abonando la cuenta B. | |
UPDATE cuentas SET saldo_cuenta = saldo_cuenta + monto WHERE nombre_cuenta = 'B'; | |
-- Asumiendo que el saldo de la cuenta A no puede ser negativo, abortamos la transacción | |
ROLLBACK; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment