Block 127: Database Design Basics
Design normalized relational database schemas.
Concepts
- Primary and foreign keys
- One-to-many and many-to-many relationships
- Normalization: 1NF, 2NF, 3NF concepts
- ERD diagrams: sketching table relationships
Code Examples
See exercise below.
Exercise
Design a schema for: students, courses, and enrollments. Write the CREATE TABLE SQL for all 3. Insert sample data and write a JOIN query to list students with their courses.
Homework
What is the N+1 query problem in databases? How do JOINs solve it?