DELETE Data
The DELETE statement is used to remove rows from a table. This chapter introduces various uses of the DELETE statement.
Basic Syntax
Delete Single Row
Delete Multiple Rows
Delete with Subquery
Delete with JOIN
Delete All Rows
TRUNCATE vs DELETE
Practical Examples
Delete Old Records
Batch Delete
Delete with Transaction
Cascade Delete
Soft Delete
Common Errors
Error 1: Forgetting WHERE Clause
Error 2: Foreign Key Constraint
Best Practices
- Always use WHERE clause
- Test with SELECT first
- Use transactions for related deletes
- Backup data before bulk deletes
- Consider soft delete for important data
- Use LIMIT for batch deletes
Performance Tips
Summary
- DELETE FROM: Remove rows
- WHERE clause: Specify which rows to delete
- TRUNCATE: Fast delete all rows
- Cascade delete: Automatic deletion of related data
- Soft delete: Mark as deleted instead of removing
Next Step: Learn ALTER Tables