DELETE
The DELETE statement removes rows matching an optional WHERE predicate from a table, enforcing foreign-key referential actions and updating all table indexes.
Syntax
DELETE FROM table_name
[WHERE filter_condition];Parameters
| Parameter | Description |
|---|---|
table_name | Target table from which rows will be removed. |
WHERE filter_condition | Optional predicate selecting which rows to delete. When omitted, all rows in the table are deleted. |
Filtered DELETE
Provide a WHERE clause to remove only rows matching your condition. WHERE supports comparisons, logical operators, IN, BETWEEN, LIKE/NOT LIKE, IS [NOT] NULL, subqueries, and vector distance predicates.
-- Delete a single row by primary key
DELETE FROM players
WHERE Id = 4;
-- Delete with compound predicates
DELETE FROM matches
WHERE PlayedOn < '2025-01-01'
AND Points = 0;
-- Delete using a subquery
DELETE FROM players
WHERE NOT EXISTS (
SELECT 1
FROM matches m
WHERE m.PlayerId = players.Id
);Full-Table DELETE
Omitting the WHERE clause removes every row in the table while preserving the table schema, constraints, and index definitions.
DELETE FROM matches;Destructive Operation
DataVo v0.4 does not have a TRUNCATE TABLE statement; DELETE FROM table_name; removes every row and executes through normal constraint, index, and transaction paths. Wrap bulk deletes inside BEGIN ... COMMIT if you need an undo boundary.
Foreign Keys & Index Maintenance
- Referential actions: Deleting a parent row checks all referencing child tables.
ON DELETE CASCADEremoves dependent child rows automatically;ON DELETE RESTRICTrejects theDELETEif any child row still references the target key. - Automatic index cleanup: Removed rows are purged from all B-Tree,
HNSW,FLAT, andCOLUMNARindexes on the table. - Unsupported clauses:
DELETE ... USINGjoins andRETURNINGclauses are not supported in DataVo v0.4.
Transactions & Rollback Behavior
Inside an explicit transaction (BEGIN ... COMMIT), DELETE does not immediately destroy committed rows on disk. Instead, deletes are buffered in TransactionContext:
- Read-your-own-writes: Subsequent
SELECT,UPDATE, andDELETEstatements inside the same transaction immediately exclude the deleted rows. - Buffered inserts: If a row was inserted earlier in the same uncommitted transaction,
DELETEdrops it from the transaction's insert buffer. - Full reversibility: Executing
ROLLBACKorROLLBACK TO SAVEPOINTcleanly discards the buffered deletes so committed rows remain untouched.
BEGIN;
DELETE FROM players WHERE Region = 'Legacy';
SAVEPOINT after_cleanup;
DELETE FROM players WHERE Score < 200;
-- Undo only the second delete
ROLLBACK TO SAVEPOINT after_cleanup;
COMMIT;Reclaiming Space with VACUUM
In legacy Disk storage mode (or when manually compacting table storage after heavy deletes), deleted rows remain as tombstones in the physical table file until compacted. Run VACUUM on a table to reclaim that space:
VACUUM players;VACUUM table_name performs three steps:
- Scans the table and strips all tombstoned (soft-deleted) rows.
- Rewrites the surviving rows into a compacted table file with fresh, contiguous internal row IDs.
- Drops and rebuilds all B-Tree indexes on the table against the new row IDs.
When You Need VACUUM
The default Lsm storage mode compacts deleted keys automatically during background/flush merges. VACUUM <table> is primarily intended for manual space reclamation in legacy Disk mode or after large one-time purges.
See Also
- INSERT: Adding new rows to a table
- UPDATE: Modifying existing rows
- CREATE TABLE: Configuring
ON DELETE CASCADEandON DELETE RESTRICTforeign keys - Transactions: Using
BEGIN,SAVEPOINT,ROLLBACK TO SAVEPOINT, andCOMMIT