CodeWithSQL.com
Home SQL Beginner Course Database Concepts

Database Concepts

Understand databases, explore relational, hierarchical, network and object-oriented types, and learn how Database Management Systems (DBMS) work.

3 Topics Chapter 2 of 8 Beginner

1 Understanding Databases

Top

Imagine a giant filing cabinet in an office. Each drawer holds folders on a specific topic — one for customers, another for orders, another for products. Each folder contains neatly organized records with the same fields: name, address, phone number. A database works exactly the same way, except it lives on a computer and can search through millions of records in milliseconds.

If you've ever used a spreadsheet, you already understand the basic idea. A database is essentially a collection of spreadsheets (called tables) that are linked together, with rules to keep the data consistent and accurate.

What Does a Database Table Look Like?

Let's start with something concrete. Here's a simple customers table and the SQL to create it:

SQL CREATE TABLE customers ( customer_id INT PRIMARY KEY, name VARCHAR(100), email VARCHAR(150), city VARCHAR(50) );

Now let's query all customers in this table:

SQL SELECT * FROM customers;
Result
customer_id | name            | email                | city
------------|-----------------|----------------------|----------
1           | Alice Johnson   | alice@example.com    | New York
2           | Bob Smith       | bob@example.com      | London
3           | Carol Martinez  | carol@example.com    | Dubai

Each row is a single record (one customer). Each column is a specific piece of information (name, email, city). The table is the container that holds all the rows together under a defined structure.

Key Database Building Blocks

Before you go further, here are the terms you'll see everywhere in this course:

TermWhat It MeansAnalogy
Table A structured collection of related data A single spreadsheet
Row (Record) One entry in a table One row in a spreadsheet
Column (Field) A specific attribute (name, email, etc.) A column header in a spreadsheet
Schema The blueprint that defines tables, columns, and data types The template for how each spreadsheet is laid out
Primary Key A unique identifier for each row (e.g., customer_id) A serial number that never repeats
Foreign Key A column that links to another table's primary key A reference number that points to another filing cabinet

How Tables Relate to Each Other

The real power of a database is that tables can be linked together. In our online store example, a customer can place multiple orders. Here's how that relationship works:

SQL CREATE TABLE orders ( order_id INT PRIMARY KEY, customer_id INT, product VARCHAR(100), amount DECIMAL(10,2), order_date DATE, FOREIGN KEY (customer_id) REFERENCES customers(customer_id) );

The customer_id column in the orders table is a foreign key — it points back to the customers table. This means every order is connected to a specific customer. Now we can ask questions that span both tables using a JOIN:

SQL SELECT c.name, o.product, o.amount FROM customers c JOIN orders o ON c.customer_id = o.customer_id ORDER BY o.amount DESC;
Result
name            | product         | amount
----------------|-----------------|--------
Alice Johnson   | Laptop          | 1299.99
Carol Martinez  | Headphones      | 199.99
Bob Smith       | Keyboard        | 79.99
Alice Johnson   | Mouse           | 29.99

Notice how Alice has two orders. The database doesn't store her name twice — it just links both orders to her customer_id. This avoids duplicate data and keeps everything consistent. You'll learn much more about JOINs in the SQL Joins chapter.

Did you know? Every app you use daily — Instagram, Netflix, your banking app — stores its data in databases. When you scroll your feed, stream a movie, or check your balance, the app is running SQL queries behind the scenes to fetch exactly the data you need.

Key Takeaways

  • A database is an organized collection of data stored in tables (think: a collection of linked spreadsheets)
  • Tables have rows (records) and columns (fields) with a defined schema
  • A primary key uniquely identifies each row; a foreign key links one table to another
  • Related tables can be combined using JOINs to answer complex questions
  • Databases avoid data duplication by splitting data across related tables

2 Different Types of Databases

Top

Not all databases are built the same way. Over the decades, different models have been invented to solve different problems. Today, the relational model dominates — and it's what you'll learn throughout this course — but understanding the alternatives gives you valuable context.

The Four Main Types at a Glance

TypeStructureExample DBBest ForStill Used?
Relational Tables with rows & columns, linked by keys MySQL, PostgreSQL, SQL Server Business apps, e-commerce, finance Dominant
Hierarchical Tree structure (parent-child) IBM IMS, Windows Registry File systems, org charts Legacy
Network Graph-like with many-to-many links IDMS, TurboIMAGE Telecom, complex networks Rare
Object-Oriented Data stored as objects (like in OOP code) db4o, ObjectDB CAD/CAM, multimedia, scientific data Niche

Relational Databases (The Star of This Course)

Relational databases organize data into tables that relate to each other through keys. This is the model proposed by Edgar F. Codd at IBM in 1970, and it remains the foundation of modern data management. When people say "database" without any qualifier, they almost always mean a relational database.

Here's a practical example. An online bookstore has two related tables:

SQL -- Authors table CREATE TABLE authors ( author_id INT PRIMARY KEY, name VARCHAR(100), country VARCHAR(50) ); -- Books table (linked to authors via foreign key) CREATE TABLE books ( book_id INT PRIMARY KEY, title VARCHAR(200), author_id INT, price DECIMAL(8,2), FOREIGN KEY (author_id) REFERENCES authors(author_id) );

Now we can query across both tables to find all books with their author names:

SQL SELECT b.title, a.name AS author, b.price FROM books b JOIN authors a ON b.author_id = a.author_id ORDER BY b.price DESC;
Result
title                        | author              | price
-----------------------------|---------------------|-------
Database Design Patterns     | Alice Chen          | 49.99
Learning SQL Step by Step    | Bob Williams        | 39.99
The Query Handbook           | Alice Chen          | 34.99

This is the kind of query you'll write throughout this course. The relational model makes it natural to store data separately (authors in one table, books in another) and combine them whenever you need to. You'll master this in the SQL Joins chapter.

Hierarchical Databases

A hierarchical database stores data in a tree structure — each record has one parent and potentially many children. Think of your computer's file system: a drive contains folders, each folder contains subfolders and files. That's a hierarchy.

IBM's IMS (Information Management System), built in the 1960s for NASA's Apollo program, is the most famous example. The Windows Registry also uses a hierarchical model. While hierarchical databases are fast for specific lookups along the tree, they're rigid — if you need to query data across branches, things get complicated fast.

Network Databases

Network databases extend the hierarchical model by allowing records to have multiple parents — creating a graph-like web of relationships. This was designed to handle many-to-many relationships that hierarchical databases couldn't.

Telecom companies used network databases like IDMS to model complex subscriber-to-service relationships. However, the complexity of navigating these networks made them hard to query and maintain. Relational databases largely replaced them by offering a simpler, more flexible approach with JOINs.

Object-Oriented Databases

Object-oriented databases store data as objects — the same way object-oriented programming languages like Java or C++ define them, complete with attributes and methods. This eliminates the need to translate between code objects and database rows.

CAD/CAM systems and multimedia applications sometimes use object-oriented databases like db4o because they deal with complex data structures (3D models, video metadata) that don't fit neatly into rows and columns. In practice, most teams choose a relational database and handle the object-to-table mapping with tools called ORMs (Object-Relational Mappers).

Course focus: This course focuses on relational databases because they power 80%+ of business applications worldwide. MySQL, PostgreSQL, and SQL Server are the tools you're most likely to encounter in your career. Once you master relational concepts, understanding other database types becomes straightforward.

Key Takeaways

  • There are four main database types: relational, hierarchical, network, and object-oriented
  • Relational databases (tables linked by keys) are the dominant model and the focus of this course
  • Hierarchical databases use a tree structure — great for file systems, but rigid for general queries
  • Network databases allow many-to-many relationships but are complex to navigate
  • Object-oriented databases store data as objects — useful in niche scenarios like CAD/CAM

3 Introduction to DBMS (Database Management System)

Top

A database is your data. A DBMS (Database Management System) is the software that manages that data. It's the engine that stores, retrieves, secures, and organizes everything. When someone says "I use MySQL" or "we run PostgreSQL," they're talking about a DBMS.

Think of it this way: if a database is a library full of books, the DBMS is the librarian — it knows where everything is, enforces the rules, handles multiple visitors at once, and keeps everything organized.

Popular DBMS Systems Compared

Here's a practical overview of the DBMS software you're most likely to encounter:

DBMSTypeLicenseBest ForUsed By
MySQL Relational Open Source (GPL) Web apps, startups, WordPress Facebook, Twitter, Airbnb
PostgreSQL Relational Open Source (PostgreSQL License) Complex queries, data integrity, GIS Apple, Instagram, Spotify
SQL Server Relational Commercial (free Express edition) Enterprise, .NET stack, Azure Microsoft, Stack Overflow, Dell
Oracle DB Relational Commercial Large enterprise, banking, ERP Banks, governments, airlines
SQLite Relational Public Domain Mobile apps, embedded, testing Every smartphone, browsers
MariaDB Relational Open Source (GPL) MySQL alternative, community-driven Wikipedia, Google, Samsung

What Does a DBMS Actually Do?

A DBMS isn't just a storage container. It provides critical services that make databases reliable and usable in the real world:

FeatureWhat It MeansPractical Example
Data Storage Efficiently stores and retrieves data on disk Fetching your order history from millions of records in milliseconds
Query Processing Parses and executes SQL commands Running SELECT * FROM orders WHERE total > 100
Security Controls who can access and modify data An intern can read reports but can't delete customer records
Concurrency Handles multiple users reading/writing at the same time 500 people booking the same flight simultaneously without conflicts
Backup & Recovery Protects data against crashes and corruption Restoring the database to exactly 2 minutes before a server failure
Data Integrity Enforces rules so data stays consistent Preventing an order from referencing a customer that doesn't exist

The Three Categories of SQL Commands

When you communicate with a DBMS, you use SQL commands that fall into three main categories. You'll study each one in depth later in this course:

CategoryFull NamePurposeKey CommandsExample
DDL Data Definition Language Define and modify database structure CREATE, ALTER, DROP CREATE TABLE users (...);
DML Data Manipulation Language Add, update, and delete data INSERT, UPDATE, DELETE INSERT INTO users VALUES (...);
DQL Data Query Language Retrieve and read data SELECT SELECT * FROM users;

Here's a quick example that uses all three categories together:

SQL -- DDL: Create the table structure CREATE TABLE products ( product_id INT PRIMARY KEY, name VARCHAR(100), price DECIMAL(10,2) ); -- DML: Insert data into the table INSERT INTO products VALUES (1, 'Wireless Mouse', 29.99); INSERT INTO products VALUES (2, 'Mechanical Keyboard', 89.99); INSERT INTO products VALUES (3, 'USB-C Hub', 45.00); -- DQL: Query the data SELECT name, price FROM products WHERE price > 30;
Result
name                 | price
---------------------|-------
Mechanical Keyboard  | 89.99
USB-C Hub            | 45.00

Practical tip: If you're just getting started, install MySQL or PostgreSQL — both are free, well-documented, and widely used in the industry. MySQL is slightly easier to set up for beginners, while PostgreSQL is more standards-compliant and feature-rich. Either one is an excellent choice for learning SQL.

Key Takeaways

  • A DBMS is the software (MySQL, PostgreSQL, SQL Server) that manages your database
  • It handles storage, security, concurrency, backup, and data integrity automatically
  • SQL commands fall into three categories: DDL (structure), DML (data changes), and DQL (queries)
  • MySQL and PostgreSQL are the best free options for beginners to start learning
  • Every major tech company runs on one or more DBMS systems

What's next? Now that you understand what databases are, the types that exist, and how a DBMS manages everything, the next chapter dives into SQL Fundamentals — you'll learn the actual syntax and rules for writing SQL queries, including how to select, filter, and sort data.