A Look Inside Relational Databases: Where Data Lives in Tables & Connects Through Keys
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.
What Makes a Relational Database โRelationalโ? ๐๏ธ
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
Understanding NULL: One of the Most Misunderstood Concepts ๐ณ๏ธ
A NULL value means โdata is not availableโ โ not zero, not blank, not unknownโฆ simply no value exists.
Key differences ๐
- 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.)
A Real-Life Analogy
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 Simple Scenario
A customer database stores:
- Age
- 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.
Schema โ The Blueprint of a Relational Database ๐๏ธ
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.
Two Types of Schema: Logical & Physical ๐ท๏ธ
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.
Logical Schema โ the conceptual structure
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.
Logical Schema Example: Library Management System ๐
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 โ
โโโโโโโโโโโโโโดโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโดโโโโโโโโโโโดโโโโโโโโโโโโ
Understanding the Relationships ๐
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.)
Why This Schema Matters for Data Access & Privacy ๐
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.
Physical Schema โ The Real, Implemented Database ๐งฑ
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.
Tables โ Where the Data Actually Lives ๐งฑ
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
Linking Tables Together ๐
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.
Fields, Primary Keys & Foreign Keys (Physical Schema) ๐
Fields โ The Columns Inside a Table ๐งฉ
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
- 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.
Primary Keys โ Unique Identifiers for Records ๐
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:
- 1๏ธโฃ Uniqueness
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.)
- 2๏ธโฃ No NULL values
A primary key can never be blank. Every record must have a valid identifier.
- 3๏ธโฃ Prefer a single field
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.
- 4๏ธโฃ Primary keys are automatically stored in an index
This index ensures uniqueness and makes record lookups extremely fast.
Foreign Keys โ Connecting One Table to Another ๐
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).
Foreign Key Constraints (Optional but Recommended)๐๏ธ
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.
NEW Physical Schema Diagram ๐
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
Primary Key vs Foreign Key (Comparison Table) ๐
| Detail | Primary Key | Foreign Key |
|---|---|---|
| Required? | Yes โ every table must have one | No โ tables can exist without foreign keys |
| # Allowed per table | Only one primary key per table | Any number of foreign keys allowed |
| Automatically Indexed? | Yes | Not always (depends on the system) |
| Duplicates Allowed? | No | Yes |
| NULL Allowed? | Never | Yes |
| Function | Uniquely identifies a record | Connects records across tables |
Indexes โ Speeding Up Searches in a Database ๐
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.
Why Indexes Matter
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.
Real-Time Scenarios That Show How Indexes Work .
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 โ A Simple Way to Enter and View Data ๐
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.
๐ Real Time Example
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 โ The Real Power Behind Databases ๐
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.
What Queries Actually Do ๐ง
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.
Beginner-Friendly Example ๐
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.
Why Queries Matter So Much
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 โ Ready-Made Answers From Your Data ๐
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.
Example
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.
Why Reports Are Helpful ๐งฉ
- 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 & Modules โ Adding Functionality to Your Database โ๏ธ
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.
Macros โ Automated Actions ๐งฉ
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.
Modules โ Custom Code for Advanced Behavior ๐งฉ๐งฉ
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.
How They Work Together ๐งต
- 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.
Wrapping Up ๐งญ
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