Database Design Skill
Use this skill when designing database schema, relationships, or data models.
Overview
Design efficient, normalized database schemas that support application requirements while maintaining data integrity.
When to Use
Use this skill when:
- Designing a new database schema
- Creating database tables
- Defining relationships between entities
- Optimizing database performance
Workflow
Step 1: Understand Requirements
- Identify entities
- Identify relationships
- Understand data access patterns
- Consider scale requirements
Questions:
- What entities exist?
- How are they related?
- What queries will be common?
- What's the expected scale?
- What are the access patterns?
Step 2: Design Entity Model
- Identify entities (tables)
- Define attributes (columns)
- Choose data types
- Define constraints
Entity Design:
- Each entity = one table
- Attributes = columns
- Choose appropriate types
- Add constraints (NOT NULL, UNIQUE)
Step 3: Design Relationships
- One-to-one relationships
- One-to-many relationships
- Many-to-many relationships
- Foreign keys
Relationship Types:
- 1:1: Rare, consider merging
- 1:Many: Foreign key in "many" side
- Many:Many: Junction table
Step 4: Normalize Database
- First Normal Form (1NF)
- Second Normal Form (2NF)
- Third Normal Form (3NF)
- Consider denormalization for performance
Normalization:
- 1NF: Atomic values, no repeating groups
- 2NF: 1NF + no partial dependencies
- 3NF: 2NF + no transitive dependencies
Step 5: Design Indexes
- Primary keys
- Foreign keys
- Frequently queried columns
- Composite indexes for multi-column queries
Index Strategy:
- Index primary keys (automatic)
- Index foreign keys
- Index frequently filtered columns
- Index columns in WHERE, JOIN, ORDER BY
Step 6: Consider Performance
- Denormalization where needed
- Partitioning for large tables
- Caching strategy
- Query optimization
Performance Considerations:
- Denormalize for read-heavy workloads
- Partition large tables
- Use appropriate indexes
- Consider materialized views
Step 7: Plan Migrations
- Version control schema
- Plan migration strategy
- Handle data migration
- Rollback strategy
Design Principles
- Normalization: Reduce redundancy
- Integrity: Enforce constraints
- Performance: Optimize for queries
- Scalability: Plan for growth
- Maintainability: Clear structure
Anti-Patterns
❌ Don't do:
- Over-normalization
- Under-normalization
- Missing indexes
- No foreign keys
- Storing computed values
- No migration strategy
✅ Do instead:
- Normalize appropriately
- Use indexes strategically
- Enforce referential integrity
- Use computed values in queries
- Plan migrations carefully
Verification
- Schema normalized
- Relationships defined
- Indexes created
- Constraints added
- Migration plan ready
Related Skills
- API Design - API data layer
- Performance Optimization - Database performance
Related Commands
- Design Command - Design database architecture
- Test Command - Test database queries
Next Steps
- API Design - Design API layer
- Performance Optimization - Optimize database performance