Content
DELETE removes records from a table. Use with caution and always include a WHERE clause.
Basic DELETE Syntax
DELETE FROM table_name WHERE condition;
Delete Specific Rows
DELETE FROM customers WHERE id = 123;
Delete with Multiple Conditions
DELETE FROM orders
WHERE status = 'cancelled' AND order_date < '2025-01-01';
Delete with Subquery
DELETE FROM order_items
WHERE order_id IN (SELECT id FROM orders WHERE status = 'cancelled');
Delete All Rows (Use Carefully!)
DELETE FROM temp_table;
-- Or use TRUNCATE for faster deletion
TRUNCATE TABLE temp_table;
Safe DELETE Practice
-- Always SELECT first to verify
SELECT * FROM orders WHERE status = 'cancelled';
-- Then DELETE
DELETE FROM orders WHERE status = 'cancelled';
Generate DELETE Queries
AI2sql helps you write safe DELETE statements with proper conditions.


