Schema Design & Table Relationships: Concept
Module: Foundational Concepts
Schema design organizes data into tables and defines relationships between them. Understanding relationship types is fundamental to building robust databases.
Four relationship types:
1. One-to-One (1:1): User ↔ UserProfile
FK in either table with UNIQUE constraint
2. One-to-Many (1:N): Customer → Orders
FK in "many" side (orders.customer_id)
3. Many-to-Many (M:N): Students ↔ Courses
Junction table with two FKs
4. Self-Referencing: Employee → Manager
FK references same table's PK
CASCADE options:
• ON DELETE CASCADE: Delete parent → delete children
• ON DELETE RESTRICT: Prevent deletion if children exist
• ON DELETE SET NULL: Delete parent → set FK to NULL
Schema design is fundamental to database architecture. Poor design leads to data inconsistencies, complex queries, and scalability issues.
Every database has relationships: customers→orders (1:N), students↔courses (M:N), employees→manager (self-referencing). Proper design prevents data inconsistencies.