PM & AI Chronicles

From Product Thinking to Prompt Engineering โ€“ One Tool at a Time

Relational Databases ๐Ÿ›ข: Understanding Tables, Keys & Connections ๐Ÿงฎ๐Ÿ”‘ โ›“๏ธ

This article builds on the ideas introduced in Database Foundations, where we looked at why databases exist, how they organize information, and why structure matters. ๐Ÿ‘‰ Database Foundations

Relational databases are one of the best examples of structured data โ€” information that is predictable, organized, and stored in a clear pattern. Instead of random formats or flexible documents, a relational database stores data in tables made of rows and columns, where each column has a defined purpose and each row represents a single record.

Because everything is neatly organized, relational databases make it easy to search, filter, update, and analyze data with high accuracy.

A relational database follows a schema โ€” a strict set of rules that defines what the data should look like. Every table, every column, and every type of data stored has a blueprint. All databases are managed by a Database Management System (DBMS).

Relational databases use a specialized version called an: RDBMS โ€” Relational Database Management System

Examples: MySQL, PostgreSQL, Oracle Database, Microsoft SQL Server

The RDBMS makes sure the database stays clean, consistent, and error-free by enforcing rules such as:

  • ๐Ÿšซ No duplicate rows
  • ๐Ÿšซ Column values should NOT be arrays or repeated groups
  • โœ”๏ธ Missing data must be represented using NULL

A NULL value means โ€œdata is not availableโ€ โ€” not zero, not blank, not unknownโ€ฆ simply no value exists.

  • 0 means something (a number representing zero).
  • NULL means nothing was provided โ€” the data is missing.
  • NULL โ‰  0
  • NULL โ‰  NULL. (Two missing values are not considered equal because we donโ€™t know if they represent the same thing.)

Imagine a form that asks: โ€œHow many cars do you own?โ€

  • If someone writes 0, it means they explicitly own zero cars.
  • If the field is left blank, we donโ€™t knowโ€”maybe they forgot, maybe the question didnโ€™t apply. That blank is NULL.

A customer database stores:

  • Age
  • Email
  • Phone
  • Loyalty Points

If a customer never gave their phone number:

  • Storing it as 0 would incorrectly imply: โ€œTheir phone number is 0.โ€
  • Storing it as NULL correctly means: โ€œWe donโ€™t have this information.

NULL helps the RDBMS differentiate between valid values and missing data, which is critical for filtering, sorting, and calculating accurately.

Every relational database follows a well-defined schema. Think of the schema as the blueprint or master plan that describes:

  • What tables exist
  • What columns does each table contain
  • What data types are allowed
  • How tables are connected
  • What forms, queries, and reports the system uses

In short, the schema is the backbone of every relational database and defines everything about how the database is organized.

Relational databases describe their design at two levels:

  • Logical Schema โ€” the high-level view of tables, fields, and relationships
  • Physical Schema โ€” how the data is actually stored on disk behind the scenes

Each of these will be discussed in detail in the sections below.

This level answers the question: โ€œWhat does the database contain and how do the tables connect?โ€. It includes:

  • Table names
  • Columns in each table
  • Relationships between tables
  • Primary & foreign keys
  • High-level data rules

Logical schemas can be drawn using any diagramming toolโ€”even a simple spreadsheet.

To make this easier for beginners, hereโ€™s a simple system with four tables .

                         Book Table
 โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
 โ”‚ Book_ID   โ”‚ Title        โ”‚ Genre     โ”‚ ISBN    โ”‚ Author_ID      โ”‚
 โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
        โ”‚
        โ”‚
        โ–ผ
                    Loan Table
 โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
 โ”‚ Loan_ID    โ”‚ Book_ID   โ”‚ Member_IDโ”‚ Loan_Date    โ”‚ Return_Dateโ”‚
 โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
        โ–ฒ                       โ”‚
        โ”‚                       โ”‚
        โ”‚                       โ–ผ
                   Member Table
 โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
 โ”‚ Member_ID โ”‚ First_Nameโ”‚ Last_Name    โ”‚ Email    โ”‚ Phone        โ”‚
 โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
        โ–ฒ
        โ”‚
        โ”‚
        โ–ผ
                  Author Table
 โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
 โ”‚ Author_ID  โ”‚ First_Name   โ”‚ Last_Name    โ”‚ Country  โ”‚ Email     โ”‚
 โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

This diagram shows how the four tables relate:

  • Author โ†’ Book (1 to many)
    • One author can write many books.
  • Book โ†’ Loan (1 to many)
    • The same book may be loaned multiple times to different members.
  • Member โ†’ Loan (1 to many)
    • A member may borrow multiple books over time.

These relationships tell the database how data should be connected, but they do not determine how data is stored physically. (That is what the physical schema will explain next.)

Because the logical schema defines exactly which tables connect, it also determines what information a user can access. Example: A member borrowing a book only needs:

  • their Member_ID, and
  • the Book_ID

Nothing in the schema connects one member to another memberโ€™s personal details โ€” so the system naturally prevents a user from seeing someone elseโ€™s email or phone number. A simple way to explain this:

โ€œA reader can check out a book, but they canโ€™t open the drawer with all other readersโ€™ personal information.โ€

The structure of the logical schema itself enforces data boundaries and maintains clean separation of information. The logical schema gives us the high-level viewโ€”tables, columns, keys, and relationshipsโ€”without worrying about storage or indexing yet.

While the logical schema describes the conceptual design of the database, the physical schema is the actual implementation inside the RDBMS. It represents the real tables, columns, keys, and relationships created within the database software. In simple words:

  • Logical schema = the plan
  • Physical schema = the build

Most relational database tools can generate a physical schema automatically from the logical design. However, it can also be built manually, table by table and column by column.

Regardless of the approach, the logical schema should always come first. Planning your database on paper (or in diagrams) helps identify mistakes, missing relationships, or unnecessary data before anything is created in the system. Catching issues early makes the actual implementation much cleaner, safer, and easier to maintain.

Before diving deeper into the physical schema, it’s important to understand the key components that make up the actual implemented database. The topics below describe how the real tables, fields, and relationships are created and managed inside an RDBMS.

In the physical schema, the most essential building blocks are tables. Tables look very similar to worksheets in a spreadsheet โ€” made up of rows and columns โ€” and they store the actual data inside the database.

A relational database can (and usually does) contain multiple tables, each designed to store a specific type of information. For example, in a library system, you might have separate tables for Books, Members, Loans, and Authors.

  • Each row in a table is called a record
  • Each column represents a specific field of information

To connect information across different tables, the data must be structured so that relationships are clear. This is usually done using identifiers (like a Customer_ID, Member_ID, or Book_ID).

Example:
A row in the Loan table uses both Member_ID and Book_ID to show which person borrowed which book. These identifiers make it easy for the database to match related records across tables.

In a physical schema, the columns of a table are called fields. Each field stores one type of data for all records in that column. Examples of fields:

  • Phone number
  • Cost
  • Zip code
  • Quantity
  • Email
  • Date of Birth

A well-designed database never mixes unrelated data in the same field. For example:

  • A field should not contain a part number for one record
  • And a cost for another

These must be separate fields because when databases are queried, the user expects a consistent type of data from each field.

Every table in a relational database must have a primary key. A primary key is one or more fields whose combined values uniquely identify each record. A primary key must follow these rules:

No two records can have the same value in the primary key fields. Example: If a table used First_Name + Last_Name as a primary key:

  • “John Smith” โ€” allowed
  • “Luke Thomas” โ€” allowed
  • Another “John Smith” โ€” not allowed
  • Another “Luke Thomas” โ€” not allowed

(This is why names make poor primary keys.)

A primary key can never be blank. Every record must have a valid identifier.

Admins usually choose a field like:

  • Customer_ID
  • Member_ID
  • Product_ID
  • Employee_ID

These auto-generated IDs are simple, clear, and guaranteed to be unique.

This index ensures uniqueness and makes record lookups extremely fast.

A foreign key is one or more fields in a table that refer to the primary key of another table. Foreign keys help the database understand how records are related. Unlike primary keys:

  • โœ”๏ธ Foreign keys can have duplicate values
  • โœ”๏ธ Foreign keys can contain NULL
  • โœ”๏ธ Multiple foreign keys can exist in one table

โ“ Why can a foreign key be NULL if it references a primary key that cannot be NULL?

Because a foreign key does not always need to point to another record. Example: A book in the library database may not have an assigned author yet:

  • Book_ID: 42
  • Author_ID: NULL

This simply means โ€œwe donโ€™t know the author yet.โ€ NULL does not violate relational rules because:

  • The foreign key exists
  • But it is not currently referencing anything
  • And that’s allowed

Only when a foreign key contains a value, it must match an existing primary key (unless constraints are disabled).

Some RDBMS tools allow administrators to place constraints on foreign keys to prevent problems such as broken relationships. Constraints can prevent:

  • โŒ 1. Entering a foreign key value that doesnโ€™t exist
    • Inserting a Loan with Book_ID = 999 when Book 999 does not exist.
  • โŒ 2. Changing a foreign key to an invalid value
    • Updating Loan.Book_ID to a book that doesnโ€™t exist.
  • โŒ 3. Deleting a primary key record that is still referenced
    • This would create orphan records.

Example: Deleting a Member while their loans still exist โ†’ the Loan table would have meaningless references.

Foreign key constraints ensure database integrity.

Using the Library Management System example (same one used in Logical Schema), here is a physical schema diagram.

Note on Key Symbols ๐Ÿ”‘๐Ÿ—๏ธ

In the diagrams used throughout this article, Primary Keys and Foreign Keys are shown using different key icons to make them easy to identify:

  • ๐Ÿ”‘ Primary Key โ€” represents the field(s) that uniquely identify each record in a table.
  • ๐Ÿ—๏ธ Foreign Key โ€” represents the field(s) that link one table to another by referencing a primary key in a different table.

These symbols visually distinguish which fields uniquely define records and which fields create relationships between tables.

                               Book Table
๐Ÿ”‘ Book_ID      Title        Genre       ISBN        โ”€โ”€โ”€โ”€โ”€โ–บ  ๐Ÿ—๏ธ Author_ID
     โ”‚
     โ”‚
     โ–ผ
                               Loan Table
๐Ÿ”‘ Loan_ID     ๐Ÿ—๏ธ Book_ID     ๐Ÿ—๏ธ Member_ID     Loan_Date     Return_Date
                    โ–ฒ               โ”‚
                    โ”‚               โ”‚
                    โ”‚               โ–ผ
                             Member Table
๐Ÿ”‘ Member_ID    First_Name    Last_Name     Email        Phone
                    โ–ฒ
                    โ”‚
                    โ”‚
                    โ–ผ
                             Author Table
๐Ÿ”‘ Author_ID    First_Name    Last_Name     Country      Email
DetailPrimary KeyForeign Key
Required?Yes โ€” every table must have oneNo โ€” tables can exist without foreign keys
# Allowed per tableOnly one primary key per tableAny number of foreign keys allowed
Automatically Indexed?YesNot always (depends on the system)
Duplicates Allowed?NoYes
NULL Allowed?NeverYes
FunctionUniquely identifies a recordConnects records across tables

Just like the index at the back of a book helps you quickly find a topic without reading every page, database indexes help the DBMS find information faster without scanning the entire table.An index is a special data structure that stores pointers to the actual rows, allowing the database to jump directly to the data it needs.

Every tableโ€™s primary key automatically gets an index. This ensures quick lookups when searching for a specific record.

Additional indexes can be created on other columns that are searched frequently โ€” such as Email, Member_ID, Book_Title, or Dates.

Indexes dramatically reduce the amount of data the database must scan, which can significantly speed up queries.

โš ๏ธ But Indexes Have a Trade-Off

While indexes make reading data much faster, they can make updates, inserts, and deletes slightly slowerโ€”because the index itself must also be updated. For that reason, database designers carefully choose index columns, focusing on the fields most commonly used in searches, filters, and joins.

Searching for a customer in a huge Customers table. Imagine a bank with 2 million customers. If a support agent searches for:

โ€œFind customer where Email = john@example.comโ€

Without an index, the database scans every single row until it finds the match. With an index on Email, the DB jumps directly to that record โ€” like flipping to the โ€œJโ€ section of a phonebook. This makes a search that takes seconds finish in milliseconds.

Forms are the screens or interfaces that people use to enter, edit, or view data in a database. They sit on top of the database tables and make interaction much easier.

โœ”๏ธ You donโ€™t need forms to have a database

A database can exist with just tables. But forms make using the database much more user-friendly โ€” especially for non-technical people.

Think of a form as a clean, guided input screen that shows only what the user needs to enter. Instead of typing data directly into a table (which looks like a spreadsheet), a form:

  • Shows one record at a time
  • Has clear labels for each field
  • May include dropdowns, date pickers, or checkboxes
  • Prevents users from entering invalid or unrelated information
  • Can hide sensitive fields from users who shouldnโ€™t see them

This protects the database from mistakes and keeps everything consistent.

Imagine a Library Management System like the example above. A librarian checks out a book for a member.

Without forms: They would have to open the Loans table and manually enter:

  • Loan_ID
  • Book_ID
  • Member_ID
  • Loan_Date
  • Return_Date

This requires:

  • Knowing the exact Book_ID
  • Knowing the exact Member_ID
  • Not mistyping anything
  • Not forgetting any fields

Itโ€™s easy to make mistakes.

With a form, the librarian just sees a simple screen: Checkout Book Form

  • Select Member (drop-down list)
  • Select Book (search box or drop-down)
  • Loan Date (auto-filled)
  • Return Date (calendar picker)

The form automatically fills the Loan_ID, validates the inputs, and sends clean data to the Loans table. It’s safer, faster, and more user-friendly.

Queries are what make a database truly useful. They allow you to search, filter, and analyze your data to find exactly what you need โ€” even if your database contains millions of records.

Without queries, a database is just a giant collection of tables. With queries, it becomes a powerful information-finding engine.

A query lets you:

  • Pull specific data from one or more tables
  • Apply filters (e.g., โ€œfind all books borrowed after July 1โ€)
  • Sort results
  • Combine data from multiple related tables
  • Generate reports
  • Answer business questions instantly

In simple terms, A query is a question you ask your database, and the database returns the exact answer.

Using the Library Management System example:

โ“ Question: โ€œWhich books are currently checked out?โ€

โœ”๏ธ Query result gives you:

  • Book title
  • Member who borrowed it
  • Loan date
  • Due date

This would be nearly impossible to find manually by scrolling through thousands of rows across multiple tables.

As your data grows, scrolling becomes unrealistic. Queries allow you to:

  • Find needles in huge haystacks
  • Avoid scanning tables manually
  • Combine information across tables
  • Get instantly actionable insights

This is why queries are considered the heart of relational databases โ€” they turn raw data into meaningful information.

Reports are structured outputs that answer specific questions using data stored in your database. Think of them as prebuilt queries that present information in a clear, organized format.

A query retrieves the raw data. A report organizes that data into something meaningful and easy to read โ€” often with totals, summaries, and formatted layouts.

Using your Library Management System: โ“ Question: โ€œHow many books were borrowed this month, and who borrowed them?โ€

A report can show:

  • Member names
  • Book titles
  • Loan dates
  • Return dates
  • Total number of loans this month

All nicely formatted โ€” maybe grouped by member or sorted by date.

  • They save time โ€” no need to write the same query again
  • They give consistent, standardized answers
  • They can be scheduled (daily, weekly, monthly)
  • Theyโ€™re easy to share with managers, departments, or users

If queries are the questions, reports are the ready-made answers.

Macros and modules are tools that let you add extra functionality, automation, and custom behavior to your database. They sit on top of your tables, forms, and queries, and help the database do things automatically or perform tasks that go beyond basic data storage.

A macro is a simple, predefined action that runs automatically when triggered. Think of macros as shortcuts or mini-robots inside your database.

Example, In the Library Management System above:

  • When a book is checked out, a macro could automatically fill the Loan_Date with todayโ€™s date.
  • Another macro could show a message if a book is already checked out before allowing a new loan.
  • A macro could automatically open a specific form when the database starts.

Macros help non-technical users automate everyday tasks without writing full code.

A module is a piece of code (often written in a scripting language like VBA in systems such as MS Access) that lets you create more complex logic than macros can handle. Modules are for situations where you need precise control, calculations, or custom operations.

โœ”๏ธ Example, Using the same library scenario:

  • A module could calculate late fees based on the number of days a book is overdue.
  • It could automatically send an email notification to members with overdue books.
  • It could validate data in a more advanced way (e.g., checking multiple conditions before saving a record).

Modules are essentially programming inside your database.

  • Macros = simple automation, easy to set up
  • Modules = more powerful logic using code

Both allow you to extend the database beyond simple data storage and retrieval.

Relational databases rely on structure, rules, and relationships to keep data organized, accurate, and easy to work with. From tables and keys to schemas, queries, and reports, each part works together to ensure information is stored consistently and retrieved efficiently.

You now have a clear picture of how RDBMS systems organize data and why they remain the backbone of many applications today.

In the next article, weโ€™ll shift from structured systems to a more flexible world โ€” Non-Relational (NoSQL) Databases, where rigid tables are replaced with document stores, key-value pairs, and horizontally scalable designs. ๐Ÿ‘‰Non-Relational Databases

This article is part of the Database Fundamentals Series โ€” where we break down what databases are, how they store information, and how data is organized, accessed, and used behind the scenes. ๐Ÿ‘‰ โ€” Database Fundamentals: Foundation of Data Storage