AI Skill Report Card
Adding Database Columns
Quick Start15 / 15
SQLALTER TABLE table_name ADD COLUMN IF NOT EXISTS column_name data_type;
Recommendation▾
Add database-specific syntax variations with complete examples for PostgreSQL, MySQL, and SQLite
Workflow12 / 15
-
Identify target table and column requirements
- Table name
- Column name
- Data type
- Constraints (if any)
-
Check if column exists (optional but recommended)
SQLSELECT column_name FROM information_schema.columns WHERE table_name = 'your_table' AND column_name = 'your_column'; -
Execute ALTER TABLE statement
SQLALTER TABLE table_name ADD COLUMN IF NOT EXISTS column_name data_type; -
Verify addition
SQL\d table_name -- PostgreSQL DESCRIBE table_name; -- MySQL
Recommendation▾
Include rollback/undo procedures (DROP COLUMN statements) for completeness
Examples18 / 20
Example 1: Input: Add a JSONB column for storing scores Output:
SQLALTER TABLE skills ADD COLUMN IF NOT EXISTS criterion_scores jsonb;
Example 2: Input: Add nullable text column with default Output:
SQLALTER TABLE users ADD COLUMN IF NOT EXISTS bio text DEFAULT '';
Example 3: Input: Add non-null integer with constraint Output:
SQLALTER TABLE products ADD COLUMN IF NOT EXISTS priority integer NOT NULL DEFAULT 1 CHECK (priority >= 1 AND priority <= 5);
Recommendation▾
Provide templates for common column patterns (timestamps, foreign keys, indexes) rather than just basic ALTER statements
Best Practices
- Always use
IF NOT EXISTSto prevent errors on re-runs - Choose appropriate data types (jsonb for JSON, text for strings, timestamp for dates)
- Consider adding defaults for non-null columns
- Use meaningful column names that follow your naming convention
- Test on development environment first
Common Pitfalls
- Forgetting
IF NOT EXISTSclause causing errors on duplicate runs - Adding non-null columns without defaults to tables with existing data
- Using reserved keywords as column names without proper quoting
- Mixing up database-specific syntax (MySQL vs PostgreSQL vs SQLite)