Welcome back, young data explorer! In Module 1, you learned what a database is. You learned that data is information. You learned that a database stores data in an organised way. You learned about tables, rows, columns, records, and primary keys. You also learned that PostgreSQL is a powerful, free database management system.
In this module, we are going to get our hands dirty. We will learn how to install PostgreSQL on a computer. We will learn how to create our first database. We will learn how to create tables and add data. We will also learn how to run simple queries to find our data.
Do not worry if you have never installed software before. We will go step by step. We will use very simple words. We will explain everything in a way that a 13-year-old can understand. We will use stories, examples from Nigeria, examples from school, and examples from home. We will use pictures made from keyboard characters (ASCII art) to help you see what we mean. By the end of this module, you will know:
This module is long because it is a complete chapter, not just short notes. Take your time. Read one lesson at a time. Do the exercises. Ask questions. Practice on your computer. Are you ready? Let us begin!
After finishing this module, you should be able to:
Tunde was a 13-year-old boy who lived in Lagos, Nigeria. He had just finished Module 1 of the Certified PostgreSQL Expert course. He was very excited. He wanted to build his own database.
Tunde's father had a small shop. The shop sold provisions: rice, beans, oil, and soap. Tunde's father wrote all his sales in a notebook. But sometimes, the notebook got wet in the rain. Sometimes, pages got torn. Tunde wanted to help his father.
"Daddy," Tunde said, "I can build a database for your shop. We can store all your sales on the computer. The rain cannot destroy it. The pages cannot tear."
His father smiled. "That sounds wonderful, Tunde. But can you do it?"
Tunde remembered his lessons. "I need to install PostgreSQL first," he said. "Then I can create a database. Then I can create a table. Then I can add data."
Tunde worked all afternoon. He installed PostgreSQL. He created a database called "shop". He created a table called "sales". He added rows for each sale.
By evening, Tunde's father could see all his sales on the computer. He could find any sale in seconds. He was very proud of his son.
Moral of the story: Installing PostgreSQL and creating a database is not hard. Anyone can learn to do it. You can help your family and community.
Install means to put software on a computer so it can be used. When you install a program, you copy the files to your computer and set them up.
You cannot use PostgreSQL until you install it. Installation puts all the necessary files in the right place.
Imagine you buy a new toy. But the toy is in pieces. You must put it together before you can play. Installing software is like putting the toy together. You prepare it for use.
When you get a new phone, you install apps like WhatsApp. The apps do not work until you install them.
In a school computer lab, the teacher installs learning software on the computers. Students can use the software after it is installed.
At home, your parents may install a game on the family computer. You can play the game after it is installed.
In a Nigerian bank, the IT team installs banking software on the computers. The tellers can use the software to serve customers.
INSTALL:
[ DOWNLOAD SOFTWARE ]
|
V
[ RUN INSTALLER ]
|
V
[ FILES ARE COPIED ]
|
V
[ SOFTWARE IS READY TO USE ]
Install means to put software on a computer so it can be used. You must install PostgreSQL before you can use it.
You learned what install means. You saw examples from home, school, and Nigeria. Now you know that installation prepares software for use.
Download means to copy a file from the internet to your computer. You download PostgreSQL from the official website.
You must download PostgreSQL before you can install it. Downloading gets the installer file onto your computer.
Imagine you want a song from a friend. Your friend sends it to your phone. That is downloading. Downloading PostgreSQL is like getting the file from the internet.
You download a game from the app store. The game is saved on your phone.
In a school computer lab, the teacher downloads learning software from the internet.
At home, you download a movie from the internet. You can watch it later.
In a Nigerian office, a worker downloads a report from a company website. The report is saved on the computer.
DOWNLOAD:
[ INTERNET ]
|
V
[ POSTGRESQL WEBSITE ]
|
V
[ DOWNLOAD BUTTON ]
|
V
[ FILE SAVED ON YOUR COMPUTER ]
Download means to copy a file from the internet to your computer. You download PostgreSQL from the official website.
You learned what download means. You saw examples from home, school, and Nigeria. Now you know how to get PostgreSQL onto your computer.
Installing PostgreSQL means running the installer program. The installer copies files to your computer and sets up PostgreSQL.
Without installation, PostgreSQL cannot run on your computer. The installer does all the hard work for you.
Imagine you buy a new bicycle. It comes in a box. You must assemble it. Installing PostgreSQL is like assembling the bicycle. You follow the steps.
You install a game on your phone. You tap "Install" and wait. The game is ready to play.
In a school computer lab, the teacher installs PostgreSQL on all computers. Students can then practice using it.
At home, you install PostgreSQL on the family computer. You can then create your own databases.
In a Nigerian bank, the IT team installs PostgreSQL on the servers. The bank can then store customer data safely.
INSTALL POSTGRESQL:
[ OPEN INSTALLER ]
|
V
[ CLICK NEXT ]
|
V
[ CHOOSE PASSWORD ]
|
V
[ CHOOSE PORT 5432 ]
|
V
[ CLICK NEXT ]
|
V
[ INSTALLATION COMPLETE ]
|
V
[ CLICK FINISH ]
Installing PostgreSQL means running the installer program. You follow the steps on the screen. You choose a password and a port.
You learned how to install PostgreSQL step by step. You saw a list of steps. Now you can install PostgreSQL on your own computer.
psql is a command line tool for PostgreSQL. It lets you type SQL commands and see the results. It is like a chat window between you and the database.
psql is the easiest way to talk to PostgreSQL. You can create databases, tables, and run queries.
Imagine you are talking to a friend. You type a message. Your friend replies. psql is like that. You type a command. PostgreSQL replies with the result.
A bank worker uses psql to find a customer's account balance.
In a school computer lab, students use psql to practice SQL commands.
At home, you use psql to create a database for your recipes.
In a Nigerian bank, psql is used to find customer accounts. The bank can find any account in seconds.
psql:
[ USER TYPES COMMAND ]
|
V
[ POSTGRESQL PROCESSES COMMAND ]
|
V
[ RESULT SHOWN ON SCREEN ]
psql is a command line tool for PostgreSQL. You use it to type SQL commands and see results.
You learned about psql. You saw examples from home, school, and Nigeria. Now you know how to talk to PostgreSQL.
A database is a place where we store data in an organised way. Creating a database means making a new empty place for your data.
You cannot store data until you create a database. The database is the container for all your tables.
Imagine you want to store your toys. You need a box first. A database is like that box. You create the box before you put toys inside.
A bank creates a database for customer accounts. The database holds all account information.
A school creates a database for student records. The database holds all student information.
At home, you create a database for your recipes. The database holds all your recipes.
In a Nigerian market, a trader creates a database for sales. The database holds all sales records.
CREATE DATABASE shop;
CREATE DATABASE:
[ TYPE: CREATE DATABASE shop; ]
|
V
[ POSTGRESQL CREATES THE DATABASE ]
|
V
[ EMPTY DATABASE NAMED "shop" IS READY ]
Creating a database means making a new empty place for your data. You use the CREATE DATABASE command.
You learned how to create a database. You saw examples from home, school, and Nigeria. Now you can create your own database.
Connecting to a database means opening it so you can work with it. You must connect before you can create tables or add data.
You cannot work inside a database until you connect to it. Connecting is like opening the door to the database.
Imagine you have a box of toys. You cannot play with the toys until you open the box. Connecting to a database is like opening the box.
A bank worker connects to the customer database to find account information.
A teacher connects to the student database to find exam scores.
At home, you connect to your recipe database to find a recipe.
In a Nigerian bank, a teller connects to the customer database. The teller can then serve the customer.
\c shop
CONNECT TO DATABASE:
[ TYPE: \c shop ]
|
V
[ POSTGRESQL CONNECTS ]
|
V
[ YOU ARE NOW INSIDE "shop" ]
|
V
[ YOU CAN CREATE TABLES ]
Connecting to a database means opening it so you can work with it. You use the \c command in psql.
You learned how to connect to a database. You saw examples from home, school, and Nigeria. Now you can open your database and start working.
A table is a grid of rows and columns in a database. Creating a table means defining its columns and their types.
You cannot store data until you create a table. The table defines what kind of data you can store.
Imagine you want to store your friends' names and phone numbers. You need a table with columns for name and phone number. Creating a table is like drawing the columns in a notebook.
A bank creates a table for customers. The table has columns for ID, name, and balance.
A school creates a table for students. The table has columns for ID, name, and score.
At home, you create a table for recipes. The table has columns for ID, name, and ingredients.
In a Nigerian market, a trader creates a table for goods. The table has columns for ID, name, and price.
CREATE TABLE sales (
id SERIAL PRIMARY KEY,
item VARCHAR(50),
price NUMERIC(10, 2),
quantity INTEGER,
sale_date DATE
);
CREATE TABLE:
[ TYPE: CREATE TABLE sales (...) ]
|
V
[ POSTGRESQL CREATES THE TABLE ]
|
V
+----+----------+-------+----------+------------+
| ID | ITEM | PRICE | QUANTITY | SALE_DATE |
+----+----------+-------+----------+------------+
| | | | | |
+----+----------+-------+----------+------------+
(empty table is ready)
Creating a table means defining its columns and their types. You use the CREATE TABLE command.
You learned how to create a table. You saw examples from home, school, and Nigeria. Now you can create your own tables.
A data type tells PostgreSQL what kind of data a column can hold. Examples include numbers, text, and dates.
Data types keep your data accurate. You cannot store a word in a number column. You cannot store a number in a date column.
Imagine you have different boxes. One box is for shoes. One box is for books. You cannot put shoes in the book box. Data types are like different boxes for different data.
A bank uses a number type for account balances. It uses a text type for customer names.
A school uses a number type for scores. It uses a text type for student names.
At home, you use a text type for recipe names. You use a number type for cooking time.
In a Nigerian market, a trader uses a number type for prices. The trader uses a text type for item names.
| Data Type | What It Stores | Example |
|---|---|---|
| INTEGER | Whole numbers | 13, 100, 2025 |
| NUMERIC | Numbers with decimals | 99.99, 1500.50 |
| VARCHAR | Text (words) | "Chika", "Lagos" |
| TEXT | Long text | "This is a long sentence." |
| DATE | Dates | 2025-01-15 |
| BOOLEAN | True or False | TRUE, FALSE |
| SERIAL | Auto-incrementing number | 1, 2, 3, 4... |
DATA TYPES: [ INTEGER ] --> [ 13, 100, 2025 ] [ NUMERIC ] --> [ 99.99, 1500.50 ] [ VARCHAR ] --> [ "Chika", "Lagos" ] [ DATE ] --> [ 2025-01-15 ] [ BOOLEAN ] --> [ TRUE, FALSE ]
Data types tell PostgreSQL what kind of data a column can hold. Common types include INTEGER, NUMERIC, VARCHAR, DATE, and BOOLEAN.
You learned about data types. You saw a table of common types. Now you know how to choose the right type for your columns.
INSERT is an SQL command that adds data to a table. You use INSERT to create new rows.
A table is empty until you add data. INSERT fills the table with information.
Imagine you have an empty notebook. You write your friend's name on the first line. INSERT is like writing on a new line in the table.
A bank uses INSERT to add a new customer to the customer table.
A school uses INSERT to add a new student to the student table.
At home, you use INSERT to add a new recipe to your recipe table.
In a Nigerian market, a trader uses INSERT to add a new sale to the sales table.
INSERT INTO sales (item, price, quantity, sale_date)
VALUES ('Rice', 5000.00, 2, '2025-01-15');
INSERT DATA:
[ TYPE: INSERT INTO sales VALUES (...) ]
|
V
[ POSTGRESQL ADDS THE ROW ]
|
V
+----+----------+-------+----------+------------+
| ID | ITEM | PRICE | QUANTITY | SALE_DATE |
+----+----------+-------+----------+------------+
| 1 | Rice | 5000 | 2 | 2025-01-15 |
+----+----------+-------+----------+------------+
(new row added)
INSERT adds data to a table. You use it to create new rows.
You learned how to add data with INSERT. You saw examples from home, school, and Nigeria. Now you can add data to your tables.
SELECT is an SQL command that finds data in a table. You use SELECT to ask questions about your data.
Data is not useful if you cannot find it. SELECT helps you find the data you need.
Imagine you have a big box of toys. You want to find your red car. You search through the box. SELECT is like searching through the table.
A bank uses SELECT to find a customer's account balance.
A school uses SELECT to find a student's exam score.
At home, you use SELECT to find a recipe for jollof rice.
In a Nigerian market, a trader uses SELECT to find all sales of rice.
SELECT * FROM sales; SELECT item, price FROM sales; SELECT * FROM sales WHERE item = 'Rice';
SELECT DATA:
[ TYPE: SELECT * FROM sales; ]
|
V
[ POSTGRESQL SEARCHES THE TABLE ]
|
V
+----+----------+-------+----------+------------+
| ID | ITEM | PRICE | QUANTITY | SALE_DATE |
+----+----------+-------+----------+------------+
| 1 | Rice | 5000 | 2 | 2025-01-15 |
+----+----------+-------+----------+------------+
(data is shown)
SELECT finds data in a table. You use it to ask questions about your data.
You learned how to find data with SELECT. You saw examples from home, school, and Nigeria. Now you can find data in your tables.
UPDATE is an SQL command that changes data in a table. You use UPDATE to fix mistakes or change information.
Data can change. Prices go up. Scores are corrected. Names are spelled differently. UPDATE keeps your data accurate.
Imagine you write your friend's phone number in your notebook. Later, your friend changes their number. You must erase the old number and write the new one. UPDATE is like erasing and writing the new number.
A bank uses UPDATE to change a customer's address.
A school uses UPDATE to correct a student's score.
At home, you use UPDATE to change a recipe's cooking time.
In a Nigerian market, a trader uses UPDATE to change the price of rice.
UPDATE sales SET price = 5500.00 WHERE item = 'Rice';
UPDATE DATA:
[ TYPE: UPDATE sales SET price = 5500 WHERE item = 'Rice'; ]
|
V
[ POSTGRESQL FINDS THE ROW ]
|
V
[ POSTGRESQL CHANGES THE PRICE ]
|
V
+----+----------+-------+----------+------------+
| ID | ITEM | PRICE | QUANTITY | SALE_DATE |
+----+----------+-------+----------+------------+
| 1 | Rice | 5500 | 2 | 2025-01-15 |
+----+----------+-------+----------+------------+
(price is updated)
UPDATE changes data in a table. You use it to fix mistakes or change information.
You learned how to update data with UPDATE. You saw examples from home, school, and Nigeria. Now you can change data in your tables.
DELETE is an SQL command that removes data from a table. You use DELETE to remove rows you no longer need.
Sometimes data is no longer needed. Old records can be removed. DELETE keeps your table clean and organised.
Imagine you have a list of old phone numbers. You do not need them anymore. You cross them out. DELETE is like crossing out old data.
A bank uses DELETE to remove a closed account.
A school uses DELETE to remove a student who has left the school.
At home, you use DELETE to remove a recipe you no longer like.
In a Nigerian market, a trader uses DELETE to remove a product that is no longer sold.
DELETE FROM sales WHERE item = 'Rice';
DELETE DATA:
[ TYPE: DELETE FROM sales WHERE item = 'Rice'; ]
|
V
[ POSTGRESQL FINDS THE ROW ]
|
V
[ POSTGRESQL REMOVES THE ROW ]
|
V
+----+----------+-------+----------+------------+
| ID | ITEM | PRICE | QUANTITY | SALE_DATE |
+----+----------+-------+----------+------------+
| | | | | |
+----+----------+-------+----------+------------+
(row is removed)
DELETE removes data from a table. You use it to remove rows you no longer need.
You learned how to delete data with DELETE. You saw examples from home, school, and Nigeria. Now you can remove data from your tables.
You can list all databases and tables in PostgreSQL. This helps you see what you have created.
If you have many databases and tables, you can get confused. Listing helps you find your way.
Imagine you have many boxes in your room. You write a list of what is inside each box. Listing databases and tables is like writing that list.
A bank lists all its databases to know what data it has.
A school lists all its tables to know what data it stores.
At home, you list all your recipes to know what you can cook.
In a Nigerian market, a trader lists all goods to know what is in stock.
\l -- list all databases \dt -- list all tables in the current database \d sales -- describe the sales table
LIST DATABASES:
[ TYPE: \l ]
|
V
+-----------+----------+----------+
| Name | Owner | Encoding |
+-----------+----------+----------+
| postgres | postgres | UTF8 |
| shop | postgres | UTF8 |
+-----------+----------+----------+
Listing databases and tables helps you see what you have created. You use \l for databases and \dt for tables.
You learned how to list databases and tables. You saw examples from home, school, and Nigeria. Now you can see what you have created.
An error is a mistake. PostgreSQL tells you when you make a mistake. You can fix the mistake and try again.
Everyone makes mistakes. Learning to fix errors makes you a better expert.
Imagine you are writing a letter. You spell a word wrong. You erase it and write it correctly. Fixing errors in PostgreSQL is like that.
A bank worker types the wrong account number. PostgreSQL shows an error. The worker corrects the number and tries again.
A student types the wrong table name. PostgreSQL shows an error. The student corrects the name and tries again.
At home, you type the wrong recipe name. PostgreSQL shows an error. You correct the name and try again.
In a Nigerian market, a trader types the wrong price. PostgreSQL shows an error. The trader corrects the price and tries again.
| Error | What It Means | How to Fix It |
|---|---|---|
| syntax error | You typed a command incorrectly | Check your spelling and punctuation |
| relation does not exist | The table does not exist | Create the table first |
| database does not exist | The database does not exist | Create the database first |
| permission denied | You do not have permission | Ask an administrator for permission |
| duplicate key value | You tried to add a duplicate primary key | Use a unique value |
ERROR:
[ TYPE: SELCT * FROM sales; ]
|
V
[ ERROR: syntax error at or near "SELCT" ]
|
V
[ FIX THE SPELLING: SELECT ]
|
V
[ TRY AGAIN ]
Errors are mistakes. PostgreSQL tells you when you make a mistake. You can fix the mistake and try again.
You learned about common errors and how to fix them. You saw a table of errors. Now you can fix mistakes in PostgreSQL.
A complete database has a database, tables, and data. You can create a complete database by following the steps.
Creating a complete database helps you practice everything you learned. You can use it for your own projects.
Imagine you build a house. You start with the foundation. Then you build the walls. Then you add the roof. Creating a complete database is like building a house. You follow the steps.
A bank creates a complete database for customer accounts.
A school creates a complete database for student records.
At home, you create a complete database for your recipes.
In a Nigerian market, a trader creates a complete database for sales.
COMPLETE DATABASE:
[ INSTALL ] --> [ CREATE DATABASE ] --> [ CONNECT ]
| | |
V V V
[ CREATE TABLE ] --> [ INSERT DATA ] --> [ SELECT DATA ]
| | |
V V V
[ UPDATE DATA ] --> [ DELETE DATA ] --> [ LIST ALL ]
|
V
[ COMPLETE DATABASE! ๐ ]
A complete database has a database, tables, and data. You can create one by following the steps.
You learned how to create a complete database. You saw a list of steps. Now you can build your own database from start to finish.
| Word | Simple Definition |
|---|---|
| Install | To put software on a computer so it can be used. |
| Download | To copy a file from the internet to your computer. |
| psql | A command line tool for PostgreSQL. |
| CREATE DATABASE | An SQL command to create a new database. |
| Connect | To open a database so you can work with it. |
| CREATE TABLE | An SQL command to create a new table. |
| Data type | Tells PostgreSQL what kind of data a column can hold. |
| INSERT | An SQL command to add data to a table. |
| SELECT | An SQL command to find data in a table. |
| UPDATE | An SQL command to change data in a table. |
| DELETE | An SQL command to remove data from a table. |
| Error | A mistake. PostgreSQL tells you when you make one. |
INSTALL POSTGRESQL
|
V
OPEN psql
|
V
CREATE DATABASE
|
V
CONNECT TO DATABASE
|
V
CREATE TABLE
|
V
INSERT DATA
|
V
SELECT DATA
|
V
SEE RESULTS!
Step 1: Learn what install means. Step 2: Download PostgreSQL. Step 3: Install PostgreSQL. Step 4: Open psql. Step 5: Create a database. Step 6: Connect to the database. Step 7: Create a table. Step 8: Learn data types. Step 9: Insert data. Step 10: Select data. Step 11: Update data. Step 12: Delete data. Step 13: List databases and tables. Step 14: Fix errors. Step 15: Create a complete database.
[ WEBSITE ] --> [ DOWNLOAD ] --> [ INSTALLER ]
|
V
[ RUN INSTALLER ]
|
V
[ CHOOSE PASSWORD ]
|
V
[ CHOOSE PORT 5432 ]
|
V
[ INSTALLATION COMPLETE ]
| Command | What It Does | Example |
|---|---|---|
| CREATE DATABASE | Creates a new database | CREATE DATABASE shop; |
| \c | Connects to a database | \c shop |
| CREATE TABLE | Creates a new table | CREATE TABLE sales (...); |
| INSERT | Adds data to a table | INSERT INTO sales VALUES (...); |
| SELECT | Finds data in a table | SELECT * FROM sales; |
| UPDATE | Changes data in a table | UPDATE sales SET ...; |
| DELETE | Removes data from a table | DELETE FROM sales WHERE ...; |
| \l | Lists all databases | \l |
| \dt | Lists all tables | \dt |
| Feature | PostgreSQL | MySQL | SQLite |
|---|---|---|---|
| Cost | Free | Free | Free |
| Power | Very powerful | Powerful | Simple |
| Best for | Large apps | Websites | Small apps |
| Security | Very strong | Strong | Basic |
| Users | Many at once | Many at once | One at a time |
In this module, you learned how to install PostgreSQL and create your first database. You learned what install means. You learned how to download PostgreSQL from the official website. You learned how to run the installer and choose a password and port. You learned how to open psql, the command line tool for PostgreSQL.
You learned how to create a database with CREATE DATABASE. You learned how to connect to a database with \c. You learned how to create a table with CREATE TABLE. You learned about data types like INTEGER, VARCHAR, and DATE.
You learned how to add data with INSERT. You learned how to find data with SELECT. You learned how to change data with UPDATE. You learned how to remove data with DELETE. You learned how to list databases and tables with \l and \dt.
You learned about common errors and how to fix them. You learned how to create a complete database from start to finish.
Now you are ready to move on to Module 3, where you will learn more advanced SQL. But before you go, make sure you understand the key takeaways below.
Match the command in Column A with what it does in Column B.
| Column A | Column B |
|---|---|
| 1. CREATE DATABASE | A. Adds data to a table |
| 2. \c | B. Finds data in a table |
| 3. CREATE TABLE | C. Creates a new database |
| 4. INSERT | D. Removes data from a table |
| 5. SELECT | E. Connects to a database |
| 6. UPDATE | F. Creates a new table |
| 7. DELETE | G. Changes data in a table |
Answers: 1-C, 2-E, 3-F, 4-A, 5-B, 6-G, 7-D
Title: Build a Class Database
Instructions: In groups of 3 or 4, create a database for your class.
Create a table for students. Add at least 5 rows of data.
Run queries to find students with high scores.
Present your database to the class.
Example:
Database: class
Table: students (id, name, age, score)
Data: 1, Chika, 13, 85; 2, Emeka, 13, 90; 3, Ngozi, 12, 78; 4, Tunde, 14, 92; 5, Fatima, 13, 88.
Query: SELECT * FROM students WHERE score > 80;
Title: My First Database
Instructions: Create a database for something you like.
Create a table. Add at least 5 rows of data. Run a query to find specific data.
Write down what you did.
Example:
Database: mybooks
Table: books (id, title, author, year)
Data: 1, Things Fall Apart, Chinua Achebe, 1958; 2, Purple Hibiscus, Chimamanda Ngozi Adichie, 2003; etc.
Query: SELECT * FROM books WHERE year > 2000;
Title: Build a Shop Database
Materials: Computer with PostgreSQL installed.
Steps:
Assignment: For one week, practice using PostgreSQL. Keep a diary. Each day, write down:
At the end of the week, write a short report. Share it with your teacher or parent.
In Module 3, you will learn more advanced SQL. You will learn about:
Before you start Module 3, make sure you understand everything in this module. Practice installing PostgreSQL. Create databases and tables. Add data. Run queries. Fix errors. When you are ready, turn the page and continue your journey to becoming a Certified PostgreSQL Expert!
End of Module 2.