The DELETE Statement
The DELETE statement removes existing records from a table.
💡 DELETE removes rows from a table. Like UPDATE, always use a WHERE clause unless you want to delete everything!
Basic Syntax
DELETE FROM table_name WHERE condition;
Delete Specific Rows
DELETE FROM customers WHERE id = 5;
DELETE FROM customers WHERE city = 'New York';
Safe Delete Pattern
-- Step 1: Preview
SELECT * FROM customers WHERE city = 'Chicago';
-- Step 2: Delete
DELETE FROM customers WHERE city = 'Chicago';
-- Step 3: Verify
SELECT * FROM customers WHERE city = 'Chicago';
DELETE vs TRUNCATE vs DROP
| Operation | Removes Data | Keeps Table | Can Use WHERE | Speed |
|---|---|---|---|---|
| DELETE | Yes | Yes | Yes | Slow |
| TRUNCATE | Yes | Yes | No | Fast |
| DROP | Yes | No | No | Fastest |
⚠️ Deleted data is usually gone forever unless you're inside a transaction. Always backup before deleting.
✅ Key Takeaways
- DELETE removes rows from a table
- Always include a WHERE clause unless deleting all rows
- Preview with SELECT before deleting
- TRUNCATE is faster for deleting all rows
- Deleted data is permanent outside of transactions