Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CREATE PROCEDURE usp_withdraw_money(account_id INT, money_amount DECIMAL(38,4))
- BEGIN
- START TRANSACTION;
- UPDATE accounts a
- SET a.balance = a.balance - money_amount
- WHERE a.id = account_id;
- IF (SELECT a.balance FROM accounts a WHERE a.id=account_id) >= 0
- THEN COMMIT ;
- ELSE
- ROLLBACK ;
- END IF;
- END;
Advertisement
Add Comment
Please, Sign In to add comment