SAVEPOINT
The SAVEPOINT
statement sets a point within a transaction to which you can roll back without affecting the entire transaction.
Example: Using SAVEPOINT
BEGIN TRANSACTION;
UPDATE FreedomFighters SET City = 'Salem' WHERE Name = 'Senthil';
SAVEPOINT SavePoint1;
UPDATE FreedomFighters SET Contribution = 'Cultural Activism' WHERE Name = 'Riya';
ROLLBACK TO SavePoint1;
COMMIT;
Output:
Changes after SavePoint1
are rolled back, but changes before the savepoint are committed.
Do's and Don'ts
Do's
- Use savepoints to manage complex transactions with partial rollbacks.
- Plan savepoints strategically to isolate parts of a transaction.
Don'ts
- Don't create too many savepoints, as it may affect performance.
- Don't rely solely on savepoints; handle errors appropriately.