DELETE permanently removes rows from a Snowflake table, either all rows or those that match a WHERE condition.
DELETE removes rows from a table and returns the number of affected rows. Without a WHERE clause, the entire table is cleared; with a condition, only matching rows disappear.
The minimal form is DELETE FROM table_name [WHERE condition];
. You can add table aliases, use sub-queries, or limit rows through JOIN-style predicates.
Supply the primary key in the WHERE clause to ensure only one row is touched.
DELETE FROM Customers WHERE id = 42;
Combine DELETE with a date filter to clean historical data safely.
DELETE FROM Orders WHERE order_date < '2023-01-01';
Yes—use IN or EXISTS to target related rows.
DELETE FROM OrderItems oi
WHERE EXISTS (
SELECT 1
FROM Orders o
WHERE o.id = oi.order_id
AND o.order_date < '2023-01-01'
);
Always test with SELECT first, wrap large deletes in transactions, and prefer predicate-based deletes over truncating whole tables when auditing matters.
Use ALTER TABLE ... RECLUSTER
or rely on automatic micro-partition pruning; Snowflake automatically manages storage but reclustering speeds queries.
Yes. Snowflake auto-commits each statement unless you explicitly start a transaction with BEGIN.
No native LIMIT. Use a sub-query with QUALIFY ROW_NUMBER() to batch deletes.
Use TIME TRAVEL: SELECT * FROM table AT(before => timestamp)
and INSERT the rows back, or clone the table at an earlier point.