Sobes.tech
Senior

Will INSERT and UPDATE be executed if there is no COMMIT in the transaction?

sobes.tech AI

Answer from AI

If an INSERT or UPDATE is performed in a transaction but COMMIT is not executed, the changes will not be committed to the database and will typically be rolled back when the session ends or a ROLLBACK is issued.

That is:

  • INSERT and UPDATE will be executed locally within the transaction, and you will be able to see the changes in the current session.
  • Without COMMIT, the changes will not be visible to other sessions and will not be saved in the database.
  • When the connection is closed or a ROLLBACK is explicitly issued, all changes will be undone.

This behavior ensures atomicity and data consistency.

Example:

BEGIN TRANSACTION;
INSERT INTO users (id, name) VALUES (1, 'Alice');
-- without COMMIT
ROLLBACK; -- changes will be undone

As a result, no new record will appear in the users table.

Will INSERT and UPDATE be executed if there is no… - sobes.tech