How to Delete Data in a Snowflake Table

To delete data from a Snowflake table, use a DELETE statement with a WHERE condition that identifies the rows to remove. Omitting the condition deletes every row but keeps the table. This guide covers a transaction-based SQL workflow, full-table cleanup, duplicate removal, Snowpark Python, and recovery after an accidental deletion.

What Deleting Data Does in Snowflake

Use row deletion when the table must remain available; drop the table only when you want to remove the table itself.

A deletion affects every row that satisfies its condition, not necessarily one row. A customer ID, status, or date can match many records, so previewing the selection matters.

Deleting rows also does not guarantee immediate physical erasure or an immediate reduction in storage charges. Historical data can remain under Snowflake’s applicable Time Travel and Fail-safe policies. Recovery depends on the table type and configured retention, not simply on whether the delete succeeded.

Before running the examples, make sure your active role has:

  • DELETE on the target table.
  • SELECT for the preview and verification queries.
  • Access to the database, schema, and warehouse used in the examples.

The SQL examples use an illustrative table named MY_DB.PUBLIC.ORDERS. Replace the database, schema, table, column names, and sample values with your actual identifiers and criteria.

How to Delete Rows Safely With SQL

Choose the operation according to what you want to keep.

Your Goal Operation Important Difference
Remove selected rows DELETE with WHERE Keeps unmatched rows and the table
Remove every row while retaining load metadata Unfiltered DELETE Keeps the table and its load metadata
Empty a table and reset its load metadata TRUNCATE TABLE Allows previously loaded files to be loaded again
Remove the table object itself DROP TABLE The table is no longer available to ordinary queries

The following steps remove orders whose status is cancelled, with an opportunity to roll back before committing.

Step 1: Confirm the Target and Preview the Rows

  1. Confirm your session context: SELECT CURRENT_ROLE(), CURRENT_DATABASE(), CURRENT_SCHEMA(), CURRENT_WAREHOUSE(); Use a fully qualified table name before proceeding.
  2. Count the rows that match your intended condition:
    SELECT COUNT(*) AS rows_to_delete
    FROM MY_DB.PUBLIC.ORDERS
    WHERE STATUS = 'cancelled';
  3. Inspect a sample using that exact condition:
    SELECT ORDER_ID, CUSTOMER_ID, STATUS, CREATED_AT
    FROM MY_DB.PUBLIC.ORDERS
    WHERE STATUS = 'cancelled'
    ORDER BY ORDER_ID
    LIMIT 20;

Stop if the count or sample is unexpected. Check spelling, capitalization in stored string values, and whether your condition needs another restriction.

If other processes are writing to the table, the matching set can change between preview and deletion. Coordinate those writes when you need the deleted set to match the preview exactly.

Step 2: Start a Transaction and Delete the Matching Rows

  1. Start an explicit transaction:
    BEGIN TRANSACTION;
  2. Execute the delete:
    DELETE FROM MY_DB.PUBLIC.ORDERS
    WHERE STATUS = 'cancelled';

Run these statements in the same session, one at a time. Inspect the rows matching your intended condition before running the DELETE.

Do not run DDL statements such as CREATE, ALTER, or DROP while relying on this rollback opportunity.

Step 3: Verify the Result, Then Commit or Roll Back

  1. Review the affected-row count returned by the delete, then check for remaining matches:
    SELECT COUNT(*) AS remaining_matches
    FROM MY_DB.PUBLIC.ORDERS
    WHERE STATUS = 'cancelled';

    With no intervening writes, the remaining count should be zero, and the affected-row count should match the reviewed selection.

  2. If the result is correct, commit:
    COMMIT;
  3. If the result is wrong, run this instead of committing:
    ROLLBACK;

Confirm that the chosen transaction command succeeds before closing the session. A rollback can undo this uncommitted deletion; it cannot undo an earlier deletion that already committed.

Delete All Rows, Date Ranges, or Duplicates

The standalone examples in this section assume autocommit is enabled and no transaction is open. They make real changes when executed, so confirm the target and selection first.

Delete All Rows Without Dropping the Table

When you intentionally want to remove every row while retaining the table and its load metadata, run:

DELETE FROM MY_DB.PUBLIC.ORDERS;

If you also want to clear the table’s load metadata, use this alternative, not both commands:

TRUNCATE TABLE MY_DB.PUBLIC.ORDERS;

Neither operation removes the table definition.

After either operation, verify that the table is empty:

SELECT COUNT(*) AS remaining_rows
FROM MY_DB.PUBLIC.ORDERS;

The result should be zero unless another process has inserted rows.

Delete Rows Within a Date Range

Use an inclusive lower boundary and an exclusive upper boundary for timestamp ranges. This avoids accidentally excluding records later on the final calendar day.

For example, preview orders created during January 2025:

SELECT COUNT(*) AS rows_to_delete
FROM MY_DB.PUBLIC.ORDERS
WHERE CREATED_AT >= '2025-01-01'::TIMESTAMP_NTZ
  AND CREATED_AT < '2025-02-01'::TIMESTAMP_NTZ;

This example assumes CREATED_AT is a TIMESTAMP_NTZ column. For time-zone-aware timestamps, use boundaries with the appropriate type and time zone.

After confirming the selection, delete it:

DELETE FROM MY_DB.PUBLIC.ORDERS
WHERE CREATED_AT >= '2025-01-01'::TIMESTAMP_NTZ
  AND CREATED_AT < '2025-02-01'::TIMESTAMP_NTZ;

Verify that the intended range is empty:

SELECT COUNT(*) AS remaining_matches
FROM MY_DB.PUBLIC.ORDERS
WHERE CREATED_AT >= '2025-01-01'::TIMESTAMP_NTZ
  AND CREATED_AT < '2025-02-01'::TIMESTAMP_NTZ;

With no intervening writes, this should return zero.

Delete Duplicate Rows While Keeping One Copy

First define what makes a row a duplicate. Matching customer IDs alone, for example, usually do not mean two orders are duplicates.

The example below assumes:

  • Your business rules define duplicates as rows with the same CUSTOMER_ID and CREATED_AT.
  • Every stored row has a genuinely unique, non-null ORDER_ID.
  • You want to keep the row with the lowest ORDER_ID.
  • Concurrent writes are paused during the cleanup.

Verify uniqueness rather than relying only on a primary-key declaration: primary keys on standard Snowflake tables generally are not enforced.

Preview the rows selected for deletion:

SELECT ORDER_ID, CUSTOMER_ID, CREATED_AT
FROM MY_DB.PUBLIC.ORDERS
QUALIFY ROW_NUMBER() OVER (
    PARTITION BY CUSTOMER_ID, CREATED_AT
    ORDER BY ORDER_ID
) > 1;

Once the selection is correct, delete those unique row IDs:

DELETE FROM MY_DB.PUBLIC.ORDERS
WHERE ORDER_ID IN (
    SELECT ORDER_ID
    FROM MY_DB.PUBLIC.ORDERS
    QUALIFY ROW_NUMBER() OVER (
        PARTITION BY CUSTOMER_ID, CREATED_AT
        ORDER BY ORDER_ID
    ) > 1
);

Verify that no duplicate groups remain under that definition:

SELECT CUSTOMER_ID, CREATED_AT, COUNT(*) AS copies
FROM MY_DB.PUBLIC.ORDERS
GROUP BY CUSTOMER_ID, CREATED_AT
HAVING COUNT(*) > 1;

The verification query should return no rows.

Do not substitute the shared duplicate key for the unique row ID in the outer delete. That can remove the survivor too. This method is not suitable for fully identical rows that have no unique row identifier: a value-based condition cannot distinguish one identical physical copy from another.

Delete Rows With Snowpark Python

Snowpark’s Table.delete API deletes rows from an existing table and returns a DeleteResult containing the affected-row count. It does not drop the table.

These examples assume you already have an authenticated Snowpark session, autocommit is enabled, and no transaction is open. They use an illustrative table named MY_DB.PUBLIC.MY_TABLE with a column named A.

Delete Rows That Match a Column Value

Preview the matching count:

t = session.table("MY_DB.PUBLIC.MY_TABLE")
print(t.filter(t["a"] == 1).count())

After confirming the selection, delete and verify:

result = t.delete(t["a"] == 1)
print(result)
print(result.rows_deleted)
print(t.filter(t["a"] == 1).count())

If the condition matches two rows, the delete result is:

DeleteResult(rows_deleted=2)

The final count should be zero if no new matching rows were inserted.

Snowpark uses block=True by default, so this call waits for the operation to complete before returning the result.

Delete Every Row While Keeping the Table

Snowpark’s default condition=None means no row filter. Calling the method without a condition therefore deletes every row: it does not remove the table object.

Preview the total first:

t = session.table("MY_DB.PUBLIC.MY_TABLE")
print(t.count())

If you intend to clear the table, execute the deletion and check the remaining count:

result = t.delete()
print(result.rows_deleted)
print(t.count())

The final count should be zero unless another writer has added rows.

Delete Rows That Match a Source DataFrame or Table

The source argument accepts a Snowpark DataFrame or another Table. When you supply source, you must also supply condition to describe how it matches the target.

For example, create and inspect a source containing the values to remove:

t = session.table("MY_DB.PUBLIC.MY_TABLE")
source_df = session.create_dataframe(
    [2, 3, 4, 5],
    schema=["a"]
)
source_df.show()
print(t.join(source_df, t["a"] == source_df["a"]).count())

After confirming those source values and the matching count, delete and verify:

result = t.delete(
    condition=t["a"] == source_df["a"],
    source=source_df
)
print(result.rows_deleted)
print(t.join(source_df, t["a"] == source_df["a"]).count())

The final join count should be zero. The operation deletes matching target rows; it does not delete rows from the source.

Run a Delete Asynchronously

Set block=False when the caller should continue without waiting. Snowpark then returns an AsyncJob rather than an immediate delete result.

After reviewing the target selection, submit the job:

t = session.table("MY_DB.PUBLIC.MY_TABLE")
condition = t["a"] == 1
job = t.delete(condition, block=False)

Your application can do independent work while the delete runs. Before reporting success or starting work that depends on the deletion, retrieve the result and verify:

result = job.result()
print(result.rows_deleted)
print(t.filter(condition).count())

Submitting a job is not proof that it finished successfully. Retrieving its result waits for completion and lets execution errors surface.

Recover Deleted Data and Verify the Final State

Recovery depends on whether the deletion is still uncommitted or historical data remains available. Once an erroneous delete has committed, stop unnecessary writes while you determine the recovery point.

Recover a Historical Copy With Time Travel

If the required historical version is still within the table’s configured Time Travel retention, you can recover it into a separate table. This avoids overwriting newer changes in the live table.

Find the accidental delete’s query ID in Snowflake query history. Use the ID of the DELETE itself, not a later verification query.

With no transaction open, create a historical clone. Replace the placeholder with the actual query ID and choose a recovery table name that does not already exist:

CREATE TABLE MY_DB.PUBLIC.ORDERS_RECOVERED
CLONE MY_DB.PUBLIC.ORDERS
BEFORE (STATEMENT => 'delete-query-id');

Inspect records you expected to recover:

SELECT ORDER_ID, CUSTOMER_ID, STATUS, CREATED_AT
FROM MY_DB.PUBLIC.ORDERS_RECOVERED
WHERE STATUS = 'cancelled'
ORDER BY ORDER_ID
LIMIT 20;

Also check the recovered table’s size:

SELECT COUNT(*) AS recovered_rows
FROM MY_DB.PUBLIC.ORDERS_RECOVERED;

The historical data is now available in ORDERS_RECOVERED; the live ORDERS table is unchanged.

Recovery will fail if the required history is unavailable, including when the relevant retention window has expired. UNDROP TABLE is not a remedy for deleted rows in a table that still exists: it applies to a dropped table.

Confirm the Cleanup and Its Upstream Cause

Before treating the cleanup as complete:

  • Record the deletion query ID, predicate, and affected-row count.
  • Check representative records that should remain, not just those you removed.
  • Validate downstream reports, joins, or application queries that depend on the data.
  • Determine whether an ingestion job can reload the removed records.

Source-system deletion does not always imply warehouse deletion. Salesforce records permanently removed at the source may remain in Snowflake tables populated by Fivetran.

Once the target table is correct, align the ingestion process with your intended deletion behavior. Otherwise, a manual cleanup can leave the warehouse and source inconsistent or allow unwanted data to be loaded again.

Frequently Asked Questions

How Do I Delete Rows Up to 1675 in Snowflake?

Snowflake tables have no inherent row order, so “up to 1675” must mean either an ID boundary or a deterministic batch of 1,675 rows. For an ID boundary, use the predicate ORDER_ID <= 1675; for a fixed batch, assuming ORDER_ID is unique and non-null, preview the selection:

SELECT ORDER_ID
FROM MY_DB.PUBLIC.ORDERS
ORDER BY CREATED_AT, ORDER_ID
LIMIT 1675;

After confirming the selection, run this with concurrent writes paused, autocommit enabled, and no open transaction:

DELETE FROM MY_DB.PUBLIC.ORDERS
WHERE ORDER_ID IN (
    SELECT ORDER_ID
    FROM MY_DB.PUBLIC.ORDERS
    ORDER BY CREATED_AT, ORDER_ID
    LIMIT 1675
);

Confirm that the affected-row count matches the selected batch, which can contain fewer rows if the table is smaller.

Does Deleting a Row in Streamlit’s Data Editor Delete It From Snowflake?

Removing a row from the editor does not, by itself, persist a deletion to Snowflake. Your application must identify the removed records, map them to stable table keys, and execute a database delete. Refresh the data from Snowflake after the database delete to confirm the result.

Why Does dbt’s Delete-and-Insert Strategy Leave Deleted Source Records in Snowflake?

The delete+insert incremental strategy replaces target rows represented in the incoming batch; it does not automatically identify every record that disappeared from the source. A partial incremental dataset cannot distinguish an unchanged record from a deleted one. To propagate hard deletes, ingest explicit deletion markers or reconcile target keys against a complete authoritative source snapshot, not against a partial delta.