热门面试题与答案和在线测试
面向面试准备、在线测试、教程与实战练习的学习平台

通过聚焦学习路径、模拟测试和面试实战内容持续提升技能。

WithoutBook 将分主题面试题、在线练习测试、教程和对比指南整合到一个响应式学习空间中。

Chapter 6

Joins, Relationships, Keys, Normalization, and Practical Data Modeling

Learn how related tables work together and how to model real systems without creating duplicate or inconsistent data.

Inside this chapter

  1. Relationships Are the Heart of Relational Databases
  2. Primary Keys and Foreign Keys
  3. Joining Tables to Produce Useful Results
  4. Normalization as a Discipline

Series navigation

Study the chapters in order for the smoothest path from relational foundations to production-level MariaDB operations. Use the navigation at the bottom of each page to move chapter by chapter through the full series.

Tutorial Home

Chapter 6

Relationships Are the Heart of Relational Databases

Relational databases become powerful when tables connect meaningfully. A customer has many orders. An order has many order items. A course has many students through an enrollment table. These relationships let you ask rich questions without duplicating the same information in multiple places.

Chapter 6

Primary Keys and Foreign Keys

CREATE TABLE order_items (
    order_item_id BIGINT PRIMARY KEY AUTO_INCREMENT,
    order_id BIGINT NOT NULL,
    product_id BIGINT NOT NULL,
    quantity INT NOT NULL,
    unit_price DECIMAL(10,2) NOT NULL,
    FOREIGN KEY (order_id) REFERENCES orders(order_id),
    FOREIGN KEY (product_id) REFERENCES products(product_id)
);

Primary keys uniquely identify rows. Foreign keys tie related records together and prevent broken references, such as an order item pointing to a product that does not exist.

Chapter 6

Joining Tables to Produce Useful Results

SELECT
    o.order_id,
    c.full_name,
    o.order_status,
    o.order_date
FROM orders o
JOIN customers c ON c.customer_id = o.customer_id
WHERE o.order_status = 'PENDING';

Joins answer real operational questions: which employee raised a request, which customer placed a payment, which department owns a project, or which student enrolled in a course. They are central to reporting and application data retrieval.

Chapter 6

Normalization as a Discipline

Normalization helps avoid repeating the same data in many places. For example, customer contact information belongs in the customer table, not copied into every order row. Product prices may be copied into order items only when you intentionally want a historical snapshot. Good design depends on understanding when duplication is harmful and when it is required for audit or performance reasons.

版权所有 © 2026,WithoutBook。