Dorothy Ideas

Database Building Tutorial: Step-by-Step Example

Building a database is a critical step in managing and organizing data efficiently. It's like creating a robust library where each book (data) has a specific shelf (table) and each shelf has a unique address (database schema). Let's dive into a practical example to understand the process.

the 7 layers of scrabble system design
the 7 layers of scrabble system design

Our example will be creating a simple library database. We'll use a relational database management system (RDBMS) like MySQL, which is widely used and SEO-friendly due to its relevance and popularity in the tech industry.

Types of Database
Types of Database

Designing the Database Schema

The first step is to design the database schema, which defines how data will be organized. For our library, we'll have three main entities: Books, Authors, and Genres.

Data Center Architecture & Design
Data Center Architecture & Design

Each entity will have its own table with relevant columns. For instance, the 'Books' table will have columns like 'id', 'title', 'author_id', 'genre_id', 'publication_year', and 'available'.

Creating Tables

Learn the key phases of database design: Collection, Analysis, Design, and Implementation. A step...
Learn the key phases of database design: Collection, Analysis, Design, and Implementation. A step...

To create these tables in MySQL, we'd use the 'CREATE TABLE' statement. Here's an example of creating the 'Books' table:

CREATE TABLE Books ( id INT AUTO_INCREMENT PRIMARY KEY, title VARCHAR(255) NOT NULL, author_id INT NOT NULL, genre_id INT NOT NULL, publication_year INT, available BOOLEAN DEFAULT TRUE, FOREIGN KEY (author_id) REFERENCES Authors(id), FOREIGN KEY (genre_id) REFERENCES Genres(id) );

Defining Relationships

SQL Cheat Sheet for Beginners
SQL Cheat Sheet for Beginners

In our schema, a book can have one author and one genre, but an author can write many books, and a genre can have many books. This is a one-to-many relationship, which we've defined using foreign keys.

Here's how the 'Authors' and 'Genres' tables would look:

CREATE TABLE Authors ( id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(255) NOT NULL );

the types of databases are shown in this graphic diagram, which shows how to use
the types of databases are shown in this graphic diagram, which shows how to use

CREATE TABLE Genres ( id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(255) NOT NULL );

Populating the Database

a diagram that shows the different types of data in each column, and how they are used
a diagram that shows the different types of data in each column, and how they are used
Is your Database Architecture is Holding You Back? Let's Fix That. Choosing the wrong database doesn’t just slow your queries—it compounds technical debt, burns budget, and limits scalability when… | Pooja Jain | 90 comments
Is your Database Architecture is Holding You Back? Let's Fix That. Choosing the wrong database doesn’t just slow your queries—it compounds technical debt, burns budget, and limits scalability when… | Pooja Jain | 90 comments
the data structure chart is shown in this diagram
the data structure chart is shown in this diagram
MySQL Sample Database
MySQL Sample Database
DBMS Roadmap 2026: Learn Database Management Systems Step by Step
DBMS Roadmap 2026: Learn Database Management Systems Step by Step
a poster with instructions on how to use the data for an organization's work
a poster with instructions on how to use the data for an organization's work
Top 15 Best Databases for Web Applications To Use In 2026
Top 15 Best Databases for Web Applications To Use In 2026
Types of Databases Explained | Hierarchical, Network, Relational, NoSQL & Distributed Databases
Types of Databases Explained | Hierarchical, Network, Relational, NoSQL & Distributed Databases
Tipos de Bases de Datos
Tipos de Bases de Datos
7 Types of Databases Every Student Should Know in 2026
7 Types of Databases Every Student Should Know in 2026
Types of Databases
Types of Databases
One wrong database choice can ruin your entire system. I’ve seen it… | Hasnain Ahmed Shaikh | 14 comments
One wrong database choice can ruin your entire system. I’ve seen it… | Hasnain Ahmed Shaikh | 14 comments
Databricks Lakehouse Architecture Guide
Databricks Lakehouse Architecture Guide
a blue computer screen with several different types of signs on the wall in front of it
a blue computer screen with several different types of signs on the wall in front of it
Mastering Access 365
Mastering Access 365
Database Design for Customer Management System
Database Design for Customer Management System
Mastering the Database Duality: Exploring the Realm of SQL and 8 Different NoSQL Databases with…
Mastering the Database Duality: Exploring the Realm of SQL and 8 Different NoSQL Databases with…
a diagram showing different types of data structures and their corresponding features, including the text
a diagram showing different types of data structures and their corresponding features, including the text
Verified: June 2026 ✅
Verified: June 2026 ✅

Once our schema is set up, we can start adding data. Let's insert some books, authors, and genres.

To insert data, we use the 'INSERT INTO' statement. Here's how we might add a book by 'George Orwell' in the 'Fiction' genre:

INSERT INTO Books (title, author_id, genre_id, publication_year) VALUES ('1984', (SELECT id FROM Authors WHERE name='George Orwell'), (SELECT id FROM Genres WHERE name='Fiction'), 1949);

Querying Data

Now that we have data, we can query it using the 'SELECT' statement. Let's find all books by 'George Orwell':

SELECT * FROM Books WHERE author_id = (SELECT id FROM Authors WHERE name='George Orwell');

Updating and Deleting Data

We can also update or delete data as needed. To update '1984' to 'Unavailable', we'd use:

UPDATE Books SET available = FALSE WHERE id = (SELECT id FROM Books WHERE title='1984');

And to delete a genre, we'd use:

DELETE FROM Genres WHERE id = (SELECT id FROM Genres WHERE name='Fiction');

In this way, we've built a simple yet functional database. This example demonstrates the core processes of database building: designing the schema, creating tables, defining relationships, populating data, querying, updating, and deleting. Each step is crucial for managing data effectively and efficiently.

Read Next