SAVEPOINT Statement
The SAVEPOINT
statement sets a point within a transaction to which you can roll back if needed. It allows partial rollback within a transaction.
Example: Using SAVEPOINT
BEGIN TRANSACTION;
UPDATE FreedomFighters SET Contribution = 'Health Reforms' WHERE Name = 'Banumathi';
SAVEPOINT SavePoint1;
DELETE FROM FreedomFighters WHERE Name = 'Senthil';
ROLLBACK TO SavePoint1;
COMMIT;
Output:
Changes up to SavePoint1
are committed; deletion of Senthil
is rolled back.
Do's and Don'ts
Do's
- Use
SAVEPOINT
to create checkpoints within complex transactions. - Roll back to specific savepoints to manage errors without undoing the entire transaction.
Don'ts
- Don't create too many savepoints, as it may impact performance.
- Don't rely solely on savepoints for transaction control; use proper error handling as well.