CertSafari
    Snowflake SnowPro Advanced: Administrator (ADA-C02)· Lessons

    Domain 4 · Lesson 17/24

    Snowflake DML Locking, Transactions and Concurrency

    Manage DML locking and concurrency in Snowflake.

    15 min read
    4% of exam
    5 sources
    Published 5 Oct 2026
    Docs as of 4 Oct 2026

    What you will be able to do

    • Explain how AUTOCOMMIT, explicit transactions and DDL statements decide where a transaction starts and ends
    • Describe when DML acquires and releases locks on a standard table, and what LOCK_TIMEOUT controls
    • Identify when deadlocks can and cannot occur, and how Snowflake resolves them
    • Apply Snowflake's recommended practices for concurrent DML, including multi-threaded clients
    • Monitor running and blocked transactions with SHOW TRANSACTIONS, SHOW LOCKS and LOCK_WAIT_HISTORY, and abort a stuck transaction with SYSTEM$ABORT_TRANSACTION

    Key concept

    Transaction-scoped locking — A statement that modifies a table takes a lock on that table, and the lock lasts until the whole transaction ends. So where the transaction ends decides how long other writers wait.

    1.Where a transaction starts and ends

    Every concurrency question in Snowflake comes back to one thing: how long a transaction stays open. A transaction is a sequence of statements that is committed or rolled back as one unit. It belongs to exactly one session, and transactions are never nested. In this topic, DML means INSERT, UPDATE, DELETE, MERGE and TRUNCATE. DDL includes CTAS as well as the other statements that define objects.

    You start a transaction explicitly with BEGIN TRANSACTION, which is the recommended synonym for BEGIN and BEGIN WORK. You end it with COMMIT or ROLLBACK. If a transaction is already active, Snowflake usually ignores a second BEGIN TRANSACTION. Avoid extra ones anyway, because they make it hard for a reader to match each COMMIT to the BEGIN it closes.

    Transactions can also start and end on their own. AUTOCOMMIT is TRUE by default. While it is on, each statement outside an explicit transaction runs as its own single-statement transaction: it commits if it succeeds and rolls back if it fails. Statements inside an explicit BEGIN TRANSACTION block are not affected by AUTOCOMMIT. When AUTOCOMMIT is off, the first DML statement after a transaction ends starts a new one implicitly. That transaction stays open until something commits or rolls it back.

    DDL works differently. Each DDL statement runs as its own transaction. If you run DDL while a transaction is active, Snowflake first commits the active transaction implicitly, then runs the DDL separately. That is why Snowflake advises that explicit transactions contain only DML and query statements. It is also why a DDL statement cannot be rolled back. An open transaction is rolled back implicitly when the session ends or when a stored procedure finishes with it still active. A transaction cannot start inside a stored procedure and finish outside it, or the reverse.

    Isolation is fixed: READ COMMITTED is the only isolation level currently supported for tables. A statement sees only data that was committed before it began, and never sees uncommitted data. Two successive statements in the same transaction can therefore see different data if another transaction commits in between. A statement does see the earlier, uncommitted changes made in its own transaction.

    Read consistency across sessions is a separate setting. By default, changes committed in one session may not be visible at once to a query in another session that started earlier. If you need queries in near-concurrent sessions to see each other's changes, an ACCOUNTADMIN can set READ_CONSISTENCY_MODE to 'GLOBAL' at the account level, at the cost of a small delay (usually milliseconds). Running dependent queries in a single session is the most recommended alternative.

    A transaction with one failing statement. If the later statements run, the COMMIT keeps rows 1 and 2sql
    CREATE TABLE table1 (i int);
    BEGIN TRANSACTION;
    INSERT INTO table1 (i) VALUES (1);
    INSERT INTO table1 (i) VALUES ('This is not a valid integer.');    -- FAILS!
    INSERT INTO table1 (i) VALUES (2);
    COMMIT;
    SELECT i FROM table1 ORDER BY i;

    Whether the later statements run depends on the client. Snowsight stops at the first error. SnowSQL with the -f option keeps going. In a Snowflake Scripting procedure, an unhandled exception means the COMMIT never runs, so the transaction is rolled back. If you want any statement error to abort the whole transaction, set TRANSACTION_ABORT_ON_ERROR at the session or account level.

    Checkpoint 1 of 6· Check yourself

    A session opens an explicit transaction, runs two UPDATEs, then runs CREATE TABLE ... AS SELECT before issuing ROLLBACK. What happens to the two UPDATEs?

    Sources1

    2.How DML locks a standard table, and how long others wait

    Once you know where a transaction ends, you can tell how long its locks last. When a statement modifies a table, it takes a lock on that table. The lock stops other statements from modifying the table until it is released. Release happens only when the whole transaction commits or rolls back, not when the statement that took the lock finishes. COMMIT itself also locks resources, but usually only briefly. Some DDL briefly locks the underlying table too: CREATE TABLE, CREATE DYNAMIC TABLE, CREATE STREAM and ALTER TABLE all do this when they set CHANGE_TRACKING = TRUE. Snowflake's docs say only UPDATE and DELETE operations are blocked by that kind of lock, and INSERT is not.

    Which DML statements can run side by side depends on their type. UPDATE, DELETE and MERGE hold locks that generally prevent them from running in parallel with other UPDATE, DELETE and MERGE statements. Most INSERT and COPY statements write only new partitions, so they often run in parallel with other INSERT and COPY operations, and sometimes in parallel with an UPDATE, DELETE or MERGE. On hybrid tables the locks are per row, so statements that touch different rows can progress together.

    This is why long jobs on a shared table end up waiting for each other. Say one job opens an explicit transaction, updates a table, then spends an hour on other statements before it commits. It holds that lock for the whole hour. With AUTOCOMMIT, each DML statement commits as soon as it succeeds, so its lock lasts only as long as that statement. A lock lasts until COMMIT or ROLLBACK, so shorter transactions mean shorter waits.

    A statement blocked by a lock waits until it either gets the lock or times out. LOCK_TIMEOUT sets that wait in seconds, and it can be set for a session. A value of 0 turns waiting off: the statement must get the lock immediately or abort. Hybrid tables use their own parameter, HYBRID_TABLE_LOCK_TIMEOUT, and take row-level locks instead of the PARTITIONS locks that SHOW LOCKS reports for standard tables.

    STATEMENT_TIMEOUT_IN_SECONDS is a different control. It limits the overall time a statement takes, including queue time, locked time, execution time and compilation time, so it also caps time spent blocked, but it is not the setting that defines the lock wait.

    The two lock-timeout parameters and what they control
    ParameterApplies toDefault (seconds)Effect of 0
    LOCK_TIMEOUTLocks on standard tables43200No waiting: get the lock immediately or abort
    HYBRID_TABLE_LOCK_TIMEOUTRow locks on hybrid tables3600No waiting: get the lock immediately or abort

    Checkpoint 2 of 6· Fill the gap

    This statement sets how long statements in the current session wait for a standard-table lock to one hour. Which parameter fills the blank?

    ALTER SESSION SET  ?  = 3600;

    Checkpoint 3 of 6· Exam question

    Two ETL jobs, each running in its own autocommit session on separate warehouses, issue a MERGE against the same standard table ORDERS_FACT. The second MERGE has been running for 30 minutes although its warehouse is idle and the first MERGE is still active. What explains this behavior?

    Sources1234

    3.When deadlocks can happen

    A deadlock happens when concurrent transactions each wait for a resource the other one has locked. Whether one is possible depends on the kind of transaction. SELECT statements are always read-only, so concurrent autocommit queries cannot deadlock, on standard or hybrid tables. Autocommit DML on standard tables cannot deadlock either. Autocommit DML on hybrid tables can.

    The risky pattern is an explicit transaction that runs several statements, because it can hold one lock while it asks for another. Snowflake detects the deadlock and picks the most recent statement involved as the victim. That statement is rolled back, but its transaction stays active and still has to be committed or rolled back. Detection can take time, so a deadlock first looks like ordinary blocking.

    Checkpoint 4 of 6· Check yourself

    Two explicit multi-statement transactions on standard tables deadlock. What does Snowflake do?

    Sources1

    4.Best practices for concurrent DML

    The rules above lead to a short list of practices.

    Keep explicit transactions short and limited to DML and query statements. Locks last until COMMIT or ROLLBACK, so every extra statement before the commit makes other writers wait longer. Keeping DDL out also stops it from silently committing your work.

    Don't run INSERT or COPY at the same time as DDL on the same object in a different session. Doing so can result in inconsistencies. If the INSERT or COPY runs in an explicit transaction, avoid DDL on that object from other sessions for the whole transaction. For example, don't insert into a table in one session while another session changes the data type of one of its columns.

    Don't mix implicit and explicit boundaries. Ending an implicitly started transaction with an explicit COMMIT is allowed, but Snowflake discourages it because the code becomes confusing. Don't change AUTOCOMMIT inside a stored procedure; doing so raises an error.

    Set LOCK_TIMEOUT deliberately. The default lets a blocked statement wait for 43200 seconds (12 hours). A lower value makes a blocked job fail early instead of holding up a pipeline.

    Be careful with multi-threaded clients. Threads that share one connection share one session, and so one transaction. If one thread runs BEGIN TRANSACTION, COMMIT or ROLLBACK, every thread on that connection is affected, and an AUTOCOMMIT change in one thread changes it for all of them. One thread can roll back another thread's work. Snowflake recommends doing at least one of these: give each thread its own connection, or run the threads synchronously. Separate connections still allow race conditions, such as one thread deleting data that another is about to update.

    Checkpoint 5 of 6· Match them up

    Match each concurrency problem to the practice the documentation gives for it

    Tap a term, then the definition that fits it.

    Sources1

    5.Monitoring and managing transaction activity

    Snowflake gives you SQL commands to see what transactions are running, who holds locks, and who is blocked. SHOW TRANSACTIONS lists running transactions for the current user, or for the whole account with IN ACCOUNT, which needs the ACCOUNTADMIN role. Each row has the transaction id, user, session, start time and state. SHOW LOCKS lists running transactions that hold or wait for locks. Its type column shows PARTITIONS for standard tables and ROW for hybrid tables, and its status column shows HOLDING or WAITING. DESCRIBE TRANSACTION takes a transaction id and reports its state, such as running, committed or aborted, even after it has ended. CURRENT_TRANSACTION returns the id of the transaction running in your own session. Neither SHOW command needs a running warehouse.

    For transactions on hybrid tables, the output is filtered. Transactions are listed only if they are blocking others or are blocked, and only once a blocked transaction has been blocked for more than 5 seconds. After it is no longer blocked, it may linger in the output for up to 15 seconds. Hybrid-table locks show as type ROW, and the resource column shows the ID of the blocking transaction.

    For history, use the Account Usage views. QUERY_HISTORY has a TRANSACTION_BLOCKED_TIME column, so filtering for values above 0 finds statements that waited on locks. The LOCK_WAIT_HISTORY view then shows, for each waiting transaction, when it requested the lock and the BLOCKER_QUERIES that held it. The first blocker query is the one running when the wait began, but earlier queries in the blocker transaction may also have taken the lock, so investigate the whole blocker transaction by joining on its transaction_id in QUERY_HISTORY.

    To manage a stuck transaction, call SYSTEM$ABORT_TRANSACTION with an id from SHOW TRANSACTIONS or SHOW LOCKS. Only the user who started the transaction or an account administrator can abort it. The function works only for explicit, multi-statement transactions; an autocommit statement is stopped by aborting its job. If a session disconnects abruptly, its transaction can be left detached and keep its locks. Snowflake aborts and rolls back such transactions on its own: after 5 minutes idle if they block another transaction on the same table, or when older than 4 hours if they block nobody. Transactions on hybrid tables are aborted after 5 minutes idle whether or not they block anyone.

    Abort a transaction identified through SHOW LOCKS IN ACCOUNTsql
    SELECT SYSTEM$ABORT_TRANSACTION(1442254688149);

    Checkpoint 6 of 6· Check yourself

    A colleague's session left a transaction holding a lock on a table, and you are not an account administrator. Who can abort it with SYSTEM$ABORT_TRANSACTION?

    Sources15

    Exam traps

    Each one states something that sounds right. Open it to see what is actually true.

    1. 1.You can undo a CREATE TABLE ... AS SELECT inside an explicit transaction by issuing ROLLBACK.Why is that wrong?

      Every DDL statement, CTAS included, runs as its own transaction and commits implicitly, so it is finished before any ROLLBACK runs.

      Covered in Where a transaction starts and ends

    2. 2.You can raise the isolation level to SERIALIZABLE for stricter protection between concurrent transactions.Why is that wrong?

      READ COMMITTED is the only isolation level currently supported for tables.

      Covered in Where a transaction starts and ends

    3. 3.A DML statement releases its lock as soon as that statement finishes.Why is that wrong?

      Locks are held until the whole transaction commits or rolls back. Statements that come later in a long explicit transaction keep the lock for the full duration.

      Covered in How DML locks a standard table, and how long others wait

    4. 4.Setting LOCK_TIMEOUT to 0 lets a statement wait for a lock indefinitely.Why is that wrong?

      0 turns lock waiting off. The statement must get the lock immediately or it aborts.

      Covered in How DML locks a standard table, and how long others wait

    5. 5.When Snowflake resolves a deadlock, the victim's transaction is closed for you.Why is that wrong?

      Only the victim statement is rolled back. Its transaction stays open and must be ended explicitly.

      Covered in When deadlocks can happen

    6. 6.SYSTEM$ABORT_TRANSACTION can abort any running statement, including autocommit ones.Why is that wrong?

      The function supports explicit multi-statement transactions only. An autocommit transaction is stopped by aborting its associated job.

      Covered in Monitoring and managing transaction activity

    Sources

    Every claim above is drawn from one of these pages, quoted as it was written on the date shown.

    1. 1.
      “The default setting for AUTOCOMMIT is TRUE (enabled).”
      ↩︎ Where a transaction starts and ends
      “Explicit transactions should contain only DML statements and query statements.”
      ↩︎ Where a transaction starts and ends
      “set the TRANSACTION_ABORT_ON_ERROR parameter at the session or account level.”
      ↩︎ Where a transaction starts and ends
      “READ COMMITTED is the only isolation level currently supported for tables.”
      ↩︎ Where a transaction starts and ends
      “set the READ_CONSISTENCY_MODE parameter to 'GLOBAL'.”
      ↩︎ Where a transaction starts and ends
      “Locks block other statements from modifying the resource until the lock is released.”
      ↩︎ How DML locks a standard table, and how long others wait
      “You can set the length of time (in seconds) that a statement should block by setting the LOCK_TIMEOUT parameter.”
      ↩︎ How DML locks a standard table, and how long others wait
      “Only UPDATE and DELETE DML operations are blocked when a table is locked. INSERT operations are not blocked.”
      ↩︎ How DML locks a standard table, and how long others wait
      “UPDATE, DELETE, and MERGE statements hold locks that generally prevent them from running in parallel with other UPDATE, DELETE, and MERGE statements.”
      ↩︎ How DML locks a standard table, and how long others wait
      “Most INSERT and COPY statements write only new partitions.”
      ↩︎ How DML locks a standard table, and how long others wait
      “Deadlocks cannot occur with autocommit DML operations on standard tables, but they can occur with autocommit DML operations on hybrid tables.”
      ↩︎ When deadlocks can happen
      “Deadlocks can occur when transactions are started explicitly and multiple statements are executed in each transaction.”
      ↩︎ When deadlocks can happen
      “multiple threads that use a single connection share the same session, and thus share the same transaction.”
      ↩︎ Best practices for concurrent DML
      “Use a separate connection for each thread.”
      ↩︎ Best practices for concurrent DML
      “Avoid executing INSERT and COPY statements concurrently with DDL statements on the same object in different sessions”
      ↩︎ Best practices for concurrent DML
      “Snowflake provides the following SQL commands to help you monitor and manage transactions and locks:”
      ↩︎ Monitoring and managing transaction activity
      “The LOCK_WAIT_HISTORY view logs a detailed history of transactions with respect to locking”
      ↩︎ Monitoring and managing transaction activity
      “Transactions are listed only if they are blocking other transactions, or if they are blocked.”
      ↩︎ Monitoring and managing transaction activity
      “Transactional operations acquire locks on a resource, such as a table, while that resource is being modified.”
      ↩︎ Key concept
      “Because a DDL statement is its own transaction, you cannot roll back a DDL statement”
      ↩︎ Exam trap 1
      “READ COMMITTED is the only isolation level currently supported for tables.”
      ↩︎ Exam trap 2
      “Locks held by a statement are released on COMMIT or ROLLBACK of the transaction.”
      ↩︎ Exam trap 3
      “A value of 0 turns off lock waiting i.e. the statement”
      ↩︎ Exam trap 4
      “The statement is rolled back, but the transaction itself remains active and must be committed or rolled back.”
      ↩︎ Exam trap 5
      “When a DML statement or CALL statement in a transaction fails, the changes made by that failed statement are rolled back.”
      ↩︎ Prediction
      “DDL statements implicitly commit active transactions”
      ↩︎ Checkpoint
      “Snowflake detects deadlocks and chooses the most recent statement that is part of the deadlock as the victim.”
      ↩︎ Checkpoint
      “Execute the threads synchronously rather than asynchronously, to control the order in which steps are performed.”
      ↩︎ Checkpoint
    2. 2.
      “The parameter setting applies to all of the time taken by the statement, including queue time, locked time, execution time, compilation time, and so on.”
      ↩︎ How DML locks a standard table, and how long others wait
    3. 3.
      “PARTITIONS (for standard table locks) or ROW (for hybrid table locks).”
      ↩︎ How DML locks a standard table, and how long others wait
    4. 4.
      “Set the lock timeout for statements executed in the session to 1 hour (3600 seconds):”
      ↩︎ How DML locks a standard table, and how long others wait
    5. 5.
      “Transactions can be aborted only by the user who started the transaction or an account administrator.”
      ↩︎ Monitoring and managing transaction activity
      “This function is supported for explicit/multi-statement transactions only.”
      ↩︎ Exam trap 6

    Continue to page 2 of 2

    Monitoring Snowflake Transactions, Locks and Blocked Queries

    Spotted a mistake, or was something unclear? Tell us.