Generador de SQL DELETE
Convierte datos CSV en sentencias SQL DELETE para eliminación dirigida de filas
Converting CSV Data to SQL DELETE Statements
Targeted row deletion — removing specific users, purging expired records, or cleaning test data — requires precise WHERE clauses that identify exactly which rows to remove. Deleting the wrong rows is often irreversible, making safe DELETE statement generation critical. The SQL DELETE Generator transforms a list of key values from CSV data into DELETE statements that target only the specified rows, with support for individual statements and optimized IN clause mode for efficient bulk deletion.
Provide your CSV data with a key column identifying rows to delete, select the target table and dialect, and receive DELETE statements that remove exactly the specified records. The tool offers both individual DELETE statements (one per row, safest for auditing) and consolidated IN clause mode (one statement with multiple keys, faster for bulk operations). All generation happens client-side with proper escaping for MySQL, PostgreSQL, and SQLite.
Individual vs Bulk DELETE Modes
The generator offers two deletion modes suited to different use cases:
- Individual statements: One DELETE per row —
DELETE FROM t WHERE id = 1;per line. Best for audit trails, controlled rollback, and when each deletion may need independent verification. - IN clause consolidation: Single statement with all keys —
DELETE FROM t WHERE id IN (1, 2, 3, ...). More efficient for bulk operations, reduces round-trips, but rolls back as one unit. - Batch IN clauses: For large key lists, splits into multiple IN clauses of configurable size (default 1000) to avoid query length limits and optimizer issues.
Safety Considerations
DELETE operations are destructive and often irreversible. The generator includes safety features:
- Mandatory key column: Every DELETE includes a WHERE clause — the tool never generates unfiltered DELETEs
- Duplicate key warning: Flags if the same key value appears multiple times in your CSV
- Row count estimation: Shows how many rows will be affected based on CSV line count
- Transaction wrapping option: Wraps all statements in BEGIN/COMMIT for atomic execution
- Pre-delete SELECT: Optional SELECT statement to preview which rows will be deleted before execution
Dialect-Specific Behavior
Different databases handle DELETE operations with varying syntax and capabilities:
- MySQL: Supports LIMIT in DELETE for incremental purging, uses backtick quoting for identifiers
- PostgreSQL: Supports DELETE with RETURNING clause to capture deleted row data for archiving before removal
- SQLite: Simpler syntax without returning clause, vacuum needed after large deletions to reclaim space
The generator produces syntactically correct statements for your chosen dialect, including appropriate identifier quoting and string escaping conventions. For PostgreSQL, the RETURNING clause is particularly valuable — it lets you capture deleted rows for audit logging or archiving in a single atomic operation rather than requiring a separate SELECT before the DELETE.
Code Examples
CSV to DELETE Statements (Both Modes)
-- Input CSV (key column: user_id):
-- user_id,reason
-- 501,spam account
-- 502,inactive > 2 years
-- 503,duplicate of 504
-- 504,requested deletion
-- Mode 1: Individual DELETE statements
DELETE FROM users WHERE user_id = 501;
DELETE FROM users WHERE user_id = 502;
DELETE FROM users WHERE user_id = 503;
DELETE FROM users WHERE user_id = 504;
-- Mode 2: Consolidated IN clause
DELETE FROM users WHERE user_id IN (501, 502, 503, 504);
-- With transaction wrapping:
BEGIN;
DELETE FROM users WHERE user_id IN (501, 502, 503, 504);
-- Verify: SELECT COUNT(*) should be 4
COMMIT; Preguntas Frecuentes
What is the IN clause mode?
IN clause mode generates a single DELETE statement with a WHERE id IN (...) clause containing all values, instead of separate DELETE statements for each row. This is more efficient for bulk deletions and reduces the number of database round-trips.
How can I avoid accidental data deletion?
The generator always produces DELETE statements with explicit WHERE clauses based on your primary key column — it never generates unqualified DELETE statements. Review the output carefully before executing, and consider running in a transaction with ROLLBACK available.
What input format does the SQL DELETE generator accept?
The generator accepts CSV data with headers. You select which column contains the identifier for deletion (primary key). Each row's value in that column becomes a condition in the WHERE clause of the generated DELETE statements.