Module 04 · Lesson 14 of 16Detailed study · about 18 min

ACID, autocommit and transaction boundaries

A transaction groups changes into one commit or rollback decision. Use it when several writes represent one business operation.

Understand the idea

Imagine transferring 10 units between two balances. Subtracting from one account without adding to the other breaks the business rule. A transaction gives the application a boundary around both writes. ACID does not invent rules such as preventing a negative balance; you must implement appropriate checks.

Key ideas in simple English
ConceptWhat it means
AtomicityCommit the intended set of changes together or undo it.
ConsistencyPreserve the rules enforced by the system and application.
IsolationControl how concurrent work observes changes.
DurabilityCommitted work remains stored after the transaction ends.
AutocommitNormally commits successful statements outside an explicit transaction.

A concrete example

The first SELECT shows 90 and 60 inside the transaction. After ROLLBACK it shows 100 and 50. After the second transaction commits it shows 90 and 60. Every total is 150. The last command removes the disposable table.

Remember: Handle the error and roll back the business operation when its writes must succeed together. Do not blindly commit the earlier successful statements.

Explain it step by step · full theory

Let us understand the idea

Imagine transferring 10 units between two balances. Subtracting from one account without adding to the other breaks the business rule. A transaction gives the application a boundary around both writes. ACID does not invent rules such as preventing a negative balance; you must implement appropriate checks.

BEGIN TRANSACTION starts the explicit unit of work. COMMIT accepts it and ROLLBACK discards its uncommitted changes. Keep all statements in the same session. Read the intermediate balance to understand what your own transaction sees.

Reason through the SQL

Prepare objects before BEGIN. DDL can commit active work and is not undone by a later rollback. A failed DML statement does not necessarily cancel earlier successful statements in the transaction; handle errors and explicitly decide whether to roll back.

The example first rehearses and rolls back, then repeats and commits. Start in a dedicated session with no unrelated transaction. The temporary table disappears when this session ends, so this demonstrates a transaction boundary rather than permanent account storage.

Words used in this lesson
Atomicity
Commit the intended set of changes together or undo it.
Consistency
Preserve the rules enforced by the system and application.
Isolation
Control how concurrent work observes changes.
Durability
Committed work remains stored after the transaction ends.
Autocommit
Normally commits successful statements outside an explicit transaction.

See how it works

Choose a step to explore the idea at your own pace.

Open the interactive explanation
Interactive explainer1 / 4

ACID, autocommit and transaction boundaries

Account 1: 100
Account 2: 50

Starting balances

Two accounts total 150.

Automatic playback is off for reduced motion. Select any step or use Previous and Next. Illustrations explain behavior; they are not live measurements.

Read the complete diagram explanation
  1. Starting balances

    Two accounts total 150.

  2. Uncommitted transfer

    Both updates are part of the same transaction.

  3. Rollback choice

    Discard both updates together.

  4. Commit choice

    Repeat the transfer and accept both changes.

Try the SQL or command

Read → predict → run in your learning environment → compare. You can also learn by reading without an account.

New to SQL? Where to run it and how to read it

A query is a question written in SQL. Snowflake runs it and returns a result table. This website shows examples; it does not connect to your account.

  1. No account yet? Read and predict the output first. Follow the account and Snowsight lesson when you are ready.
  2. For SQL practice, use a learning account in Snowsight and select an authorized role and warehouse. A role determines permissions; a warehouse supplies processing power. Follow the example’s database/schema setup when it refers to stored objects.
  3. Read the entire example, including comments beginning with --. Run the selected statement or labeled block in the stated order. Examples labeled Python, shell or HTTP belong in that client, not in a SQL editor.
  4. Compare values and row counts with the explained result. If an example deliberately causes an error, follow its rollback and cleanup steps before continuing.
SELECT / FROM
Choose the values to return / identify their input.
VALUES / COLUMN1
VALUES supplies tiny example rows. COLUMN1 means their first column, COLUMN2 their second.
AS / WITH
AS gives a result a readable name. WITH names a temporary query step within one statement.
NULL / ::
NULL means missing or unknown. The :: notation converts a value to a named data type.
Session
One connection and its settings. Keep related transaction steps in the same session.
Database.schema.table
A full address for stored data. It is separate from the warehouse that processes queries.

Need the L2_OBJECTS_LAB setup? Open the first database-object lesson →

Help with common practice errors
  • No active warehouse: select a warehouse your role can use. Do not assume you need to create a new one.
  • Object missing or not authorized: check the full name, required setup and active role. Ask the account owner for access if needed.
  • Object already exists: setup may already have run. Read the current state or choose a fresh lab name consistently; do not add OR REPLACE blindly.
  • Different result: check whether an earlier INSERT or UPDATE changed the data. VALUES examples provide their own fresh input for each statement.

Before running this lesson

Manual single-session lab. Complete Module 03 database/schema setup first. Use an authorized role with CREATE TABLE and an active warehouse. Run setup once; use a fresh disposable name if M4_BALANCES already exists. Do not run these commands inside unrelated work. Confirm AUTOCOMMIT is enabled for setup; do not change it in a session with unrelated work.

Rehearse, rollback, then commit a transfer

SQL · example
USE DATABASE L2_OBJECTS_LAB;
USE SCHEMA SALES;
CREATE TEMPORARY TABLE M4_BALANCES (ID NUMBER, BALANCE NUMBER(10,2));
INSERT INTO M4_BALANCES VALUES (1,100),(2,50);
SHOW PARAMETERS LIKE 'AUTOCOMMIT' IN SESSION;
BEGIN TRANSACTION;
UPDATE M4_BALANCES SET BALANCE=BALANCE-10 WHERE ID=1;
UPDATE M4_BALANCES SET BALANCE=BALANCE+10 WHERE ID=2;
SELECT * FROM M4_BALANCES ORDER BY ID;
ROLLBACK;
SELECT * FROM M4_BALANCES ORDER BY ID;
BEGIN TRANSACTION;
UPDATE M4_BALANCES SET BALANCE=BALANCE-10 WHERE ID=1;
UPDATE M4_BALANCES SET BALANCE=BALANCE+10 WHERE ID=2;
COMMIT;
SELECT * FROM M4_BALANCES ORDER BY ID;
DROP TABLE M4_BALANCES;

What to expect and why

The first SELECT shows 90 and 60 inside the transaction. After ROLLBACK it shows 100 and 50. After the second transaction commits it shows 90 and 60. Every total is 150. The last command removes the disposable table.

Check your understanding

Choose an answer, then check your reasoning. This is practice, not a scored test.

If the second UPDATE fails, should you assume the first UPDATE is automatically undone?

Try it yourself

Explain why CREATE TABLE belongs before BEGIN in this exercise.

Compare your reasoning

DDL has its own transaction behavior and can commit active work. Create the disposable table first so the explicit transaction groups only the intended transfer writes.

Official sources and curriculum

Module 04 · See module scope