Skip to main content
MySQL Basics
CHAPTER 03 Beginner

Understanding Relational Databases

Updated: May 16, 2026
6 min read

# CHAPTER 3

Understanding Relational Databases

1. Introduction

Before you write a single line of SQL code, you must understand the architecture of the house you are building. If you design a database poorly from the start, it will become slow, bloated, and impossible to manage as your app grows. Relational databases are built on a strict, highly organized theory. In this chapter, we will learn the anatomy of a database table, how tables link together, and the golden rule of Database Normalization.

2. Learning Objectives

By the end of this chapter, you will be able to:
  • Define Tables, Rows, and Columns in database architecture.
  • Explain what a Relational Database is.
  • Understand the concept of Database Normalization.
  • Identify the dangers of Data Redundancy.

3. The Anatomy of a Database

A database is essentially a collection of Tables. A table is exactly like a single sheet in an Excel workbook.

Let's imagine a Users table:

idfirstnameemailcreatedat
1Johnjohn@email.com2024-01-01
2Sarahsarah@email.com2024-01-05
  • Columns (Fields/Attributes): The vertical pillars (id, firstname, email). They define *what kind* of data the table holds. Every column must have a strict data type (e.g., id must be a number, firstname must be text).
  • Rows (Records): The horizontal lines. A single row represents one complete entity (e.g., one specific user).

4. What Makes it "Relational"?

Imagine you run an E-commerce store. A user buys a product. *The Wrong Way (The Spreadsheet Way):* You have one massive table called Orders. It contains: Order ID, Product Name, Product Price, User First Name, User Last Name, User Address, User Phone. If John makes 50 purchases, you have to type his Name, Address, and Phone number 50 different times into the Orders table! This is called Data Redundancy. If John changes his phone number, you have to find and update 50 rows!

*The Right Way (The Relational Way):* You break the data into two separate tables:

  1. 1. Users Table (Contains John's name, address, phone. John only exists here ONCE).
  1. 2. Orders Table (Contains Order ID, Product, and exactly one number: userid = 1).

The userid inside the Orders table acts as a bridge. It creates a Relationship pointing back to John in the Users table. If John changes his phone number, you only update it in ONE place.

5. Database Normalization (The Golden Rule)

Normalization is the process of organizing a database to reduce data redundancy and improve data integrity. The core philosophy is: Every piece of data should exist in exactly one place.

The Steps of Normalization (Simplified):

  1. 1. First Normal Form (1NF): Eliminate repeating groups. Every cell in a table must contain a single, atomic value. (e.g., You cannot have a column called phonenumbers containing "555-1234, 555-9876". You must break them apart).
  1. 2. Second Normal Form (2NF): Ensure that every non-key column is fully dependent on the primary key. Create separate tables for sets of values that apply to multiple records.
  1. 3. Third Normal Form (3NF): Eliminate transitive dependencies. If a column's value can be calculated from another column, it shouldn't be stored. (e.g., Do not store DateofBirth AND CurrentAge. Just store DateofBirth and calculate the age on the fly).

6. Primary Keys and Foreign Keys (Preview)

To link tables together, we use special columns:
  • Primary Key (PK): A unique identifier for a row in its own table (e.g., John is id: 1 in the Users table).
  • Foreign Key (FK): A column in a *different* table that holds a Primary Key from another table (e.g., the userid: 1 in the Orders table).

*(We will cover these extensively in Chapters 12 and 13).*

7. Common Mistakes

  • The "God Table": Beginners often try to put every single piece of data an application generates into one massive table with 100 columns. This breaks normalization, slows down the database, and makes the app unmaintainable. Break your data down into small, focused tables (Users, Orders, Products, Reviews).
  • Storing Calculated Data: As mentioned in 3NF, do not create a column called OrderTotal if you already have a Subtotal and Tax column. Calculated columns take up useless hard drive space and risk becoming inaccurate if the Subtotal changes but the Total is forgotten. Calculate math during the SELECT query.

8. Best Practices

  • Plan on Paper First: Before opening MySQL to type CREATE TABLE, draw a visual map of your tables on a whiteboard or a piece of paper. Draw lines showing how the Users table connects to the Posts table. This is called an ER Diagram (Entity-Relationship Diagram).

9. Exercises

  1. 1. Define the difference between a Column (Field) and a Row (Record) in a database table.
  1. 2. If an E-commerce database stores a customer's ShippingAddress inside the Users table, and also copies the exact same ShippingAddress into the Orders table for every purchase, which database design principle is being violated?

10. MCQ Quiz with Answers

Question 1

What is the primary goal of Database Normalization?

Question 2

In a Relational Database, how do two distinct tables (like Users and Orders) communicate or link with one another?

11. Interview Questions

  • Q: Explain the concept of Data Redundancy and provide a real-world example of how it can cause an application to fail or display incorrect information.
  • Q: In your own words, describe the core requirement of the First Normal Form (1NF) in database design.

12. FAQs

Q: If I split my data into 5 different tables, won't it be harder to get all the data back out at the same time? A: Excellent question! Yes, it requires a slightly more complex command. We use a SQL feature called a JOIN to temporarily stitch the tables back together when we need the data. We will master JOINs in Chapter 14!

13. Summary

Relational Databases derive their immense power from organization. By adhering to the principles of Normalization, we eliminate redundant data, prevent update errors, and create a scalable architecture where tables are neatly linked together via relationships.

14. Next Chapter Recommendation

You understand the theory; now it is time to write code. In Chapter 4: Creating Databases and Tables, we will open the MySQL Command Line and write our very first SQL statements to construct a robust database architecture.

Finish this Chapter

Save your progress on your learning path and prepare for coding interview challenges.

Discussion

Join the discussion

Log in or create a free account to participate.

Sort: ·