#1 India's Top IT Training Institute
×

About Uncodemy

Know more about who we are and what we stand for.

About Us

About Us

Discover our mission to equip individuals with essential IT skills and industry expertise.

Read More →
UnCodeMy Gallery

UnCodeMy Gallery

Explore highlights from our IT training sessions and success stories.

Read More →
Mentors

Mentors

Meet the industry experts who train and guide you through your course.

Read More →
Free Resources

Free Resources

Free tutorials, interview questions, tools and calculators to help you learn.

Explore →
×

Free Resources

Learn, practice and plan your career — bilkul free.

Tutorials

Tutorials

Step-by-step written tutorials to learn any technology at your own pace.

Read More →
Free Counselling

Free Counselling

Book a free video counselling session and pick the right course for you.

Read More →
Online Compiler

Online Compiler

Write, run and test your code online — no setup required.

Read More →
SQL for Testers

TCL : Commit, Roleback, SavePoint

COMMIT

Permanently saves all changes made in the current transaction, e.g. COMMIT; — after this, the changes cannot be undone with ROLLBACK.

ROLLBACK

Undoes changes made in the current transaction that have not yet been committed, e.g. ROLLBACK; — extremely useful in testing to reset data after a destructive test.

SAVEPOINT

Marks a point within a transaction that you can roll back to without undoing the entire transaction, e.g. SAVEPOINT before_update; ... ROLLBACK TO before_update;

Why Testers Use TCL

Wrapping test data changes in transactions with savepoints lets testers safely experiment with data changes and cleanly revert them afterward, keeping the test environment consistent.

A Worked Transaction: Testing a Money Transfer

Transactions are easiest to understand with a transfer between two bank accounts. Both updates must succeed together, or neither should happen. Here is how a tester can walk through it in MySQL:

START TRANSACTION;

UPDATE accounts SET balance = balance - 500 WHERE id = 1;   -- debit
SAVEPOINT after_debit;

UPDATE accounts SET balance = balance + 500 WHERE id = 2;   -- credit

SELECT id, balance FROM accounts WHERE id IN (1, 2);        -- inspect

ROLLBACK TO SAVEPOINT after_debit;   -- undo only the credit
SELECT id, balance FROM accounts WHERE id IN (1, 2);        -- debit still applied

ROLLBACK;                            -- undo everything, back to the start

Step by step, the first update takes money from account 1 and the savepoint marks that moment. The second update adds money to account 2. Rolling back to the savepoint removes only the credit, and the transaction stays open. The final ROLLBACK cancels the debit too, so both balances return to their starting values. If the outcome were correct, COMMIT would make it permanent instead.

This is a good way to check what other sessions can see. Open a second connection while the transaction is still open: under the default isolation level, it should not see the uncommitted balances.

Syntax Differences Between Databases

The ideas are the same everywhere, but keywords and default behaviour vary, so check which database your application uses.

DatabaseStartSavepointRoll back to itNotes
MySQL (InnoDB)START TRANSACTIONSAVEPOINT s1ROLLBACK TO SAVEPOINT s1Autocommit is on by default; DDL statements commit implicitly
PostgreSQLBEGINSAVEPOINT s1ROLLBACK TO SAVEPOINT s1Most DDL can be rolled back inside a transaction
SQL ServerBEGIN TRANSACTIONSAVE TRANSACTION s1ROLLBACK TRANSACTION s1Autocommit unless a transaction is started
OracleStarts automatically with the first changeSAVEPOINT s1ROLLBACK TO s1DDL statements commit implicitly

In MySQL, transactions only work on storage engines that support them, such as InnoDB. Changes to an older MyISAM table are saved immediately and cannot be rolled back.

Common Mistakes and a Tester's Checklist

  • Autocommit in your SQL client. Many tools commit each statement as soon as it runs. If you did not explicitly start a transaction, a later ROLLBACK has nothing to undo.
  • Leaving a transaction open. Uncommitted changes can hold row locks, making the application under test hang or time out. Always finish with COMMIT or ROLLBACK.
  • Running DDL in the middle. In MySQL and Oracle, a CREATE or ALTER commits everything before it, so earlier test changes become permanent.
  • Assuming a savepoint ends the transaction. Rolling back to a savepoint keeps the transaction open; you still need a final commit or rollback.

What to verify when testing transactional features

  • A failure halfway through, such as an invalid account number in the second step, leaves no partial changes behind.
  • Two users acting on the same record at once do not corrupt the data.
  • Application error messages appear when the database rolls back, instead of a false success screen.
  • Test data created during a run is rolled back or cleaned up, so the next run starts from a known state.

Ready to master real-world software testing?

Learn manual and automation testing hands-on with mentor-led sessions.

Explore Course