ALTER Tables
The ALTER TABLE statement is used to modify the structure of existing tables. This chapter introduces how to use ALTER TABLE to add, drop, or modify columns and constraints.
Basic Syntax
Add Columns
Drop Columns
Modify Columns
MODIFY - Change Column Definition
CHANGE - Rename and Modify Column
Rename Table
Add Constraints
Drop Constraints
Modify Table Options
Practical Examples
Add Timestamp Fields
Best Practices
- Backup data before modification
- Execute during off-peak hours
- Use online DDL for large tables
- Test in development environment first
- Use transactions (if supported)
Summary
- ADD: Add columns or constraints
- DROP: Remove columns or constraints
- MODIFY: Change column definition
- CHANGE: Rename and modify column
- RENAME: Rename table
Next Step: Learn DROP Tables