Hiring Partners
Segilola Resources Operating LimitedTaviatech TechnologiesFCMBMTN NigeriaAdvans La Fayette Microfinance BankAboki AfricaFirst Bank of NigeriaOPay
โ† Certified PostgreSQL Expert ยท Lesson 3 of 7

Installing PostgreSQL and Creating Your First Database

๐Ÿ“– Every lesson in this course is free to read right here, no account needed. Create a free account to track your progress, take the exam, and earn your certificate.
3
Module 2: Certified PostgreSQL Expert โ€“ Installing PostgreSQL and Creating Your First Database

๐Ÿ“˜ Module 2: Certified PostgreSQL Expert โ€” Installing PostgreSQL and Creating Your First Database

๐Ÿ”Ž Module Introduction

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:

  • How to download and install PostgreSQL.
  • How to open the PostgreSQL command line tool (psql).
  • How to create a database.
  • How to create a table.
  • How to add data to a table.
  • How to run simple queries to find your data.
  • How to update and delete data.

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!

๐ŸŽฏ Learning Objectives

After finishing this module, you should be able to:

  1. Explain what installation means in your own simple words.
  2. Download PostgreSQL from the official website.
  3. Install PostgreSQL on a computer.
  4. Open the psql command line tool.
  5. Create a new database using SQL.
  6. Create a table with columns and a primary key.
  7. Add data to a table using INSERT.
  8. Find data using SELECT.
  9. Update data using UPDATE.
  10. Delete data using DELETE.
  11. List all databases and tables.
  12. Understand common errors and how to fix them.

๐Ÿ“– Warm-up Story: Tunde Builds His First Database

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.

๐Ÿ“š Lesson 1: What Does "Install" Mean?

Definition

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.

Why It Is Important

You cannot use PostgreSQL until you install it. Installation puts all the necessary files in the right place.

Simple Explanation

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.

Real-Life Example

When you get a new phone, you install apps like WhatsApp. The apps do not work until you install them.

School Example

In a school computer lab, the teacher installs learning software on the computers. Students can use the software after it is installed.

Home Example

At home, your parents may install a game on the family computer. You can play the game after it is installed.

Nigerian Example

In a Nigerian bank, the IT team installs banking software on the computers. The tellers can use the software to serve customers.

Illustration (ASCII)

   INSTALL:
   [ DOWNLOAD SOFTWARE ]
         |
         V
   [ RUN INSTALLER ]
         |
         V
   [ FILES ARE COPIED ]
         |
         V
   [ SOFTWARE IS READY TO USE ]
  

Mini Summary

Install means to put software on a computer so it can be used. You must install PostgreSQL before you can use it.

Summary of Lesson 1

You learned what install means. You saw examples from home, school, and Nigeria. Now you know that installation prepares software for use.

๐Ÿ“š Lesson 2: Downloading PostgreSQL

Definition

Download means to copy a file from the internet to your computer. You download PostgreSQL from the official website.

Why It Is Important

You must download PostgreSQL before you can install it. Downloading gets the installer file onto your computer.

Simple Explanation

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.

Real-Life Example

You download a game from the app store. The game is saved on your phone.

School Example

In a school computer lab, the teacher downloads learning software from the internet.

Home Example

At home, you download a movie from the internet. You can watch it later.

Nigerian Example

In a Nigerian office, a worker downloads a report from a company website. The report is saved on the computer.

Illustration (ASCII)

   DOWNLOAD:
   [ INTERNET ]
         |
         V
   [ POSTGRESQL WEBSITE ]
         |
         V
   [ DOWNLOAD BUTTON ]
         |
         V
   [ FILE SAVED ON YOUR COMPUTER ]
  

Mini Summary

Download means to copy a file from the internet to your computer. You download PostgreSQL from the official website.

Summary of Lesson 2

You learned what download means. You saw examples from home, school, and Nigeria. Now you know how to get PostgreSQL onto your computer.

๐Ÿ“š Lesson 3: Installing PostgreSQL Step by Step

Definition

Installing PostgreSQL means running the installer program. The installer copies files to your computer and sets up PostgreSQL.

Why It Is Important

Without installation, PostgreSQL cannot run on your computer. The installer does all the hard work for you.

Simple Explanation

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.

Real-Life Example

You install a game on your phone. You tap "Install" and wait. The game is ready to play.

School Example

In a school computer lab, the teacher installs PostgreSQL on all computers. Students can then practice using it.

Home Example

At home, you install PostgreSQL on the family computer. You can then create your own databases.

Nigerian Example

In a Nigerian bank, the IT team installs PostgreSQL on the servers. The bank can then store customer data safely.

Steps to Install PostgreSQL

  1. Go to the official PostgreSQL website: www.postgresql.org
  2. Click on "Download".
  3. Choose your operating system (Windows, Mac, or Linux).
  4. Download the installer file.
  5. Double-click the installer file to run it.
  6. Follow the instructions on the screen.
  7. Choose a password for the postgres user. Remember this password!
  8. Choose the default port (5432).
  9. Click "Next" until installation is complete.
  10. Click "Finish".

Illustration (ASCII)

   INSTALL POSTGRESQL:
   [ OPEN INSTALLER ]
         |
         V
   [ CLICK NEXT ]
         |
         V
   [ CHOOSE PASSWORD ]
         |
         V
   [ CHOOSE PORT 5432 ]
         |
         V
   [ CLICK NEXT ]
         |
         V
   [ INSTALLATION COMPLETE ]
         |
         V
   [ CLICK FINISH ]
  

Mini Summary

Installing PostgreSQL means running the installer program. You follow the steps on the screen. You choose a password and a port.

Summary of Lesson 3

You learned how to install PostgreSQL step by step. You saw a list of steps. Now you can install PostgreSQL on your own computer.

๐Ÿ“š Lesson 4: Opening the psql Command Line Tool

Definition

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.

Why It Is Important

psql is the easiest way to talk to PostgreSQL. You can create databases, tables, and run queries.

Simple Explanation

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.

Real-Life Example

A bank worker uses psql to find a customer's account balance.

School Example

In a school computer lab, students use psql to practice SQL commands.

Home Example

At home, you use psql to create a database for your recipes.

Nigerian Example

In a Nigerian bank, psql is used to find customer accounts. The bank can find any account in seconds.

Illustration (ASCII)

   psql:
   [ USER TYPES COMMAND ]
         |
         V
   [ POSTGRESQL PROCESSES COMMAND ]
         |
         V
   [ RESULT SHOWN ON SCREEN ]
  

Mini Summary

psql is a command line tool for PostgreSQL. You use it to type SQL commands and see results.

Summary of Lesson 4

You learned about psql. You saw examples from home, school, and Nigeria. Now you know how to talk to PostgreSQL.

๐Ÿ“š Lesson 5: Creating a Database

Definition

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.

Why It Is Important

You cannot store data until you create a database. The database is the container for all your tables.

Simple Explanation

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.

Real-Life Example

A bank creates a database for customer accounts. The database holds all account information.

School Example

A school creates a database for student records. The database holds all student information.

Home Example

At home, you create a database for your recipes. The database holds all your recipes.

Nigerian Example

In a Nigerian market, a trader creates a database for sales. The database holds all sales records.

SQL Command to Create a Database

   CREATE DATABASE shop;
  

Illustration (ASCII)

   CREATE DATABASE:
   [ TYPE: CREATE DATABASE shop; ]
         |
         V
   [ POSTGRESQL CREATES THE DATABASE ]
         |
         V
   [ EMPTY DATABASE NAMED "shop" IS READY ]
  

Mini Summary

Creating a database means making a new empty place for your data. You use the CREATE DATABASE command.

Summary of Lesson 5

You learned how to create a database. You saw examples from home, school, and Nigeria. Now you can create your own database.

๐Ÿ“š Lesson 6: Connecting to a Database

Definition

Connecting to a database means opening it so you can work with it. You must connect before you can create tables or add data.

Why It Is Important

You cannot work inside a database until you connect to it. Connecting is like opening the door to the database.

Simple Explanation

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.

Real-Life Example

A bank worker connects to the customer database to find account information.

School Example

A teacher connects to the student database to find exam scores.

Home Example

At home, you connect to your recipe database to find a recipe.

Nigerian Example

In a Nigerian bank, a teller connects to the customer database. The teller can then serve the customer.

SQL Command to Connect

   \c shop
  

Illustration (ASCII)

   CONNECT TO DATABASE:
   [ TYPE: \c shop ]
         |
         V
   [ POSTGRESQL CONNECTS ]
         |
         V
   [ YOU ARE NOW INSIDE "shop" ]
         |
         V
   [ YOU CAN CREATE TABLES ]
  

Mini Summary

Connecting to a database means opening it so you can work with it. You use the \c command in psql.

Summary of Lesson 6

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.

๐Ÿ“š Lesson 7: Creating a Table

Definition

A table is a grid of rows and columns in a database. Creating a table means defining its columns and their types.

Why It Is Important

You cannot store data until you create a table. The table defines what kind of data you can store.

Simple Explanation

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.

Real-Life Example

A bank creates a table for customers. The table has columns for ID, name, and balance.

School Example

A school creates a table for students. The table has columns for ID, name, and score.

Home Example

At home, you create a table for recipes. The table has columns for ID, name, and ingredients.

Nigerian Example

In a Nigerian market, a trader creates a table for goods. The table has columns for ID, name, and price.

SQL Command to Create a Table

   CREATE TABLE sales (
       id SERIAL PRIMARY KEY,
       item VARCHAR(50),
       price NUMERIC(10, 2),
       quantity INTEGER,
       sale_date DATE
   );
  

Illustration (ASCII)

   CREATE TABLE:
   [ TYPE: CREATE TABLE sales (...) ]
         |
         V
   [ POSTGRESQL CREATES THE TABLE ]
         |
         V
   +----+----------+-------+----------+------------+
   | ID | ITEM     | PRICE | QUANTITY | SALE_DATE  |
   +----+----------+-------+----------+------------+
   |    |          |       |          |            |
   +----+----------+-------+----------+------------+
   (empty table is ready)
  

Mini Summary

Creating a table means defining its columns and their types. You use the CREATE TABLE command.

Summary of Lesson 7

You learned how to create a table. You saw examples from home, school, and Nigeria. Now you can create your own tables.

๐Ÿ“š Lesson 8: Data Types in PostgreSQL

Definition

A data type tells PostgreSQL what kind of data a column can hold. Examples include numbers, text, and dates.

Why It Is Important

Data types keep your data accurate. You cannot store a word in a number column. You cannot store a number in a date column.

Simple Explanation

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.

Real-Life Example

A bank uses a number type for account balances. It uses a text type for customer names.

School Example

A school uses a number type for scores. It uses a text type for student names.

Home Example

At home, you use a text type for recipe names. You use a number type for cooking time.

Nigerian Example

In a Nigerian market, a trader uses a number type for prices. The trader uses a text type for item names.

Common Data Types in PostgreSQL

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...

Illustration (ASCII)

   DATA TYPES:
   [ INTEGER ] --> [ 13, 100, 2025 ]
   [ NUMERIC ] --> [ 99.99, 1500.50 ]
   [ VARCHAR ] --> [ "Chika", "Lagos" ]
   [ DATE ]    --> [ 2025-01-15 ]
   [ BOOLEAN ] --> [ TRUE, FALSE ]
  

Mini Summary

Data types tell PostgreSQL what kind of data a column can hold. Common types include INTEGER, NUMERIC, VARCHAR, DATE, and BOOLEAN.

Summary of Lesson 8

You learned about data types. You saw a table of common types. Now you know how to choose the right type for your columns.

๐Ÿ“š Lesson 9: Adding Data with INSERT

Definition

INSERT is an SQL command that adds data to a table. You use INSERT to create new rows.

Why It Is Important

A table is empty until you add data. INSERT fills the table with information.

Simple Explanation

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.

Real-Life Example

A bank uses INSERT to add a new customer to the customer table.

School Example

A school uses INSERT to add a new student to the student table.

Home Example

At home, you use INSERT to add a new recipe to your recipe table.

Nigerian Example

In a Nigerian market, a trader uses INSERT to add a new sale to the sales table.

SQL Command to Insert Data

   INSERT INTO sales (item, price, quantity, sale_date)
   VALUES ('Rice', 5000.00, 2, '2025-01-15');
  

Illustration (ASCII)

   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)
  

Mini Summary

INSERT adds data to a table. You use it to create new rows.

Summary of Lesson 9

You learned how to add data with INSERT. You saw examples from home, school, and Nigeria. Now you can add data to your tables.

๐Ÿ“š Lesson 10: Finding Data with SELECT

Definition

SELECT is an SQL command that finds data in a table. You use SELECT to ask questions about your data.

Why It Is Important

Data is not useful if you cannot find it. SELECT helps you find the data you need.

Simple Explanation

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.

Real-Life Example

A bank uses SELECT to find a customer's account balance.

School Example

A school uses SELECT to find a student's exam score.

Home Example

At home, you use SELECT to find a recipe for jollof rice.

Nigerian Example

In a Nigerian market, a trader uses SELECT to find all sales of rice.

SQL Command to Select Data

   SELECT * FROM sales;
   SELECT item, price FROM sales;
   SELECT * FROM sales WHERE item = 'Rice';
  

Illustration (ASCII)

   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)
  

Mini Summary

SELECT finds data in a table. You use it to ask questions about your data.

Summary of Lesson 10

You learned how to find data with SELECT. You saw examples from home, school, and Nigeria. Now you can find data in your tables.

๐Ÿ“š Lesson 11: Updating Data with UPDATE

Definition

UPDATE is an SQL command that changes data in a table. You use UPDATE to fix mistakes or change information.

Why It Is Important

Data can change. Prices go up. Scores are corrected. Names are spelled differently. UPDATE keeps your data accurate.

Simple Explanation

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.

Real-Life Example

A bank uses UPDATE to change a customer's address.

School Example

A school uses UPDATE to correct a student's score.

Home Example

At home, you use UPDATE to change a recipe's cooking time.

Nigerian Example

In a Nigerian market, a trader uses UPDATE to change the price of rice.

SQL Command to Update Data

   UPDATE sales
   SET price = 5500.00
   WHERE item = 'Rice';
  

Illustration (ASCII)

   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)
  

Mini Summary

UPDATE changes data in a table. You use it to fix mistakes or change information.

Summary of Lesson 11

You learned how to update data with UPDATE. You saw examples from home, school, and Nigeria. Now you can change data in your tables.

๐Ÿ“š Lesson 12: Deleting Data with DELETE

Definition

DELETE is an SQL command that removes data from a table. You use DELETE to remove rows you no longer need.

Why It Is Important

Sometimes data is no longer needed. Old records can be removed. DELETE keeps your table clean and organised.

Simple Explanation

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.

Real-Life Example

A bank uses DELETE to remove a closed account.

School Example

A school uses DELETE to remove a student who has left the school.

Home Example

At home, you use DELETE to remove a recipe you no longer like.

Nigerian Example

In a Nigerian market, a trader uses DELETE to remove a product that is no longer sold.

SQL Command to Delete Data

   DELETE FROM sales
   WHERE item = 'Rice';
  

Illustration (ASCII)

   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)
  

Mini Summary

DELETE removes data from a table. You use it to remove rows you no longer need.

Summary of Lesson 12

You learned how to delete data with DELETE. You saw examples from home, school, and Nigeria. Now you can remove data from your tables.

๐Ÿ“š Lesson 13: Listing Databases and Tables

Definition

You can list all databases and tables in PostgreSQL. This helps you see what you have created.

Why It Is Important

If you have many databases and tables, you can get confused. Listing helps you find your way.

Simple Explanation

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.

Real-Life Example

A bank lists all its databases to know what data it has.

School Example

A school lists all its tables to know what data it stores.

Home Example

At home, you list all your recipes to know what you can cook.

Nigerian Example

In a Nigerian market, a trader lists all goods to know what is in stock.

SQL Commands to List

   \l          -- list all databases
   \dt         -- list all tables in the current database
   \d sales    -- describe the sales table
  

Illustration (ASCII)

   LIST DATABASES:
   [ TYPE: \l ]
         |
         V
   +-----------+----------+----------+
   | Name      | Owner    | Encoding |
   +-----------+----------+----------+
   | postgres  | postgres | UTF8     |
   | shop      | postgres | UTF8     |
   +-----------+----------+----------+
  

Mini Summary

Listing databases and tables helps you see what you have created. You use \l for databases and \dt for tables.

Summary of Lesson 13

You learned how to list databases and tables. You saw examples from home, school, and Nigeria. Now you can see what you have created.

๐Ÿ“š Lesson 14: Common Errors and How to Fix Them

Definition

An error is a mistake. PostgreSQL tells you when you make a mistake. You can fix the mistake and try again.

Why It Is Important

Everyone makes mistakes. Learning to fix errors makes you a better expert.

Simple Explanation

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.

Real-Life Example

A bank worker types the wrong account number. PostgreSQL shows an error. The worker corrects the number and tries again.

School Example

A student types the wrong table name. PostgreSQL shows an error. The student corrects the name and tries again.

Home Example

At home, you type the wrong recipe name. PostgreSQL shows an error. You correct the name and try again.

Nigerian Example

In a Nigerian market, a trader types the wrong price. PostgreSQL shows an error. The trader corrects the price and tries again.

Common Errors and Solutions

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

Illustration (ASCII)

   ERROR:
   [ TYPE: SELCT * FROM sales; ]
         |
         V
   [ ERROR: syntax error at or near "SELCT" ]
         |
         V
   [ FIX THE SPELLING: SELECT ]
         |
         V
   [ TRY AGAIN ]
  

Mini Summary

Errors are mistakes. PostgreSQL tells you when you make a mistake. You can fix the mistake and try again.

Summary of Lesson 14

You learned about common errors and how to fix them. You saw a table of errors. Now you can fix mistakes in PostgreSQL.

๐Ÿ“š Lesson 15: Your First Complete Database

Definition

A complete database has a database, tables, and data. You can create a complete database by following the steps.

Why It Is Important

Creating a complete database helps you practice everything you learned. You can use it for your own projects.

Simple Explanation

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.

Real-Life Example

A bank creates a complete database for customer accounts.

School Example

A school creates a complete database for student records.

Home Example

At home, you create a complete database for your recipes.

Nigerian Example

In a Nigerian market, a trader creates a complete database for sales.

Steps to Create a Complete Database

  1. Install PostgreSQL.
  2. Open psql.
  3. Create a database: CREATE DATABASE myshop;
  4. Connect to the database: \c myshop
  5. Create a table: CREATE TABLE sales (...);
  6. Add data: INSERT INTO sales VALUES (...);
  7. Find data: SELECT * FROM sales;
  8. Update data: UPDATE sales SET ... WHERE ...;
  9. Delete data: DELETE FROM sales WHERE ...;
  10. List databases: \l
  11. List tables: \dt

Illustration (ASCII)

   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! ๐ŸŽ‰ ]
  

Mini Summary

A complete database has a database, tables, and data. You can create one by following the steps.

Summary of Lesson 15

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.

๐Ÿ“– Key Vocabulary

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.

๐Ÿง  Important Concepts

  • Install means to put software on a computer. You must install PostgreSQL before you can use it.
  • Download means to copy a file from the internet. You download PostgreSQL from the official website.
  • psql is a command line tool. You use it to type SQL commands and see results.
  • CREATE DATABASE makes a new empty place for your data.
  • Connect means to open a database. You use \c to connect.
  • CREATE TABLE defines columns and their types.
  • Data types keep your data accurate. Common types include INTEGER, VARCHAR, and DATE.
  • INSERT adds data to a table.
  • SELECT finds data in a table.
  • UPDATE changes data in a table.
  • DELETE removes data from a table.
  • Errors are mistakes. You can fix them and try again.

๐Ÿ“ Step-by-Step Explanations

How to Install PostgreSQL (Step by Step)

  1. Go to the official PostgreSQL website: www.postgresql.org
  2. Click on "Download".
  3. Choose your operating system (Windows, Mac, or Linux).
  4. Download the installer file.
  5. Double-click the installer file to run it.
  6. Follow the instructions on the screen.
  7. Choose a password for the postgres user. Remember this password!
  8. Choose the default port (5432).
  9. Click "Next" until installation is complete.
  10. Click "Finish".

How to Create a Database (Step by Step)

  1. Open psql.
  2. Type: CREATE DATABASE myshop;
  3. Press Enter.
  4. PostgreSQL creates the database.
  5. Type: \c myshop
  6. Press Enter.
  7. You are now connected to the database.
  8. You can now create tables.

How to Create a Table (Step by Step)

  1. Connect to your database.
  2. Type: CREATE TABLE sales (
  3. Type: id SERIAL PRIMARY KEY,
  4. Type: item VARCHAR(50),
  5. Type: price NUMERIC(10, 2),
  6. Type: quantity INTEGER,
  7. Type: sale_date DATE
  8. Type: );
  9. Press Enter.
  10. PostgreSQL creates the table.

๐ŸŒ Real-Life Examples

  • A bank installs PostgreSQL to store customer accounts.
  • A school installs PostgreSQL to store student records.
  • A hospital installs PostgreSQL to store patient records.
  • A market trader uses PostgreSQL to track sales.
  • A library uses PostgreSQL to track borrowed books.
  • A government uses PostgreSQL to store citizen information.
  • A supermarket uses PostgreSQL to track stock.
  • A family uses PostgreSQL to store recipes.

๐Ÿ‡ณ๐Ÿ‡ฌ Nigerian Examples

  • In Lagos, a bank installs PostgreSQL to store customer accounts.
  • In Abuja, a government office installs PostgreSQL to store citizen records.
  • In Enugu, a school installs PostgreSQL to store student scores.
  • In Kano, a market trader installs PostgreSQL to track sales.
  • In Port Harcourt, a hospital installs PostgreSQL to store patient records.
  • In Ibadan, a family installs PostgreSQL to store recipes.
  • In Jos, a library installs PostgreSQL to track borrowed books.
  • In Nigeria, many companies use PostgreSQL because it is free and powerful.

๐Ÿ˜„ Fun Examples Children Can Relate To

  • Imagine installing PostgreSQL is like building a Lego set. You follow the instructions.
  • Think of psql as a chat window with a robot. You type a command. The robot replies.
  • Pretend CREATE DATABASE is like opening a new empty box for your toys.
  • Imagine INSERT is like writing a new line in your notebook.
  • Think of SELECT as a search engine for your data. You ask a question. You get an answer.

๐Ÿ  Everyday Examples

  • You install apps on your phone.
  • You download music from the internet.
  • You write a shopping list.
  • You find a contact in your phone.
  • You update a contact's phone number.
  • You delete an old message.
  • You list your tasks for the day.
  • You correct a mistake in your homework.

๐Ÿ‘จโ€๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ฆ Parent Tips

  • Help your children install PostgreSQL on a family computer.
  • Show your children how to create a simple database.
  • Practice creating tables and adding data together.
  • Encourage your children to ask questions about SQL.
  • Help your children practice finding data with SELECT.
  • Teach your children to fix errors patiently.
  • Celebrate when your child creates their first complete database.
  • Support your child if they want to learn more about databases.

๐Ÿค“ Interesting Facts

  • PostgreSQL is used by Instagram, Spotify, and Reddit.
  • psql is one of the oldest command line tools still in use.
  • A database can store billions of records.
  • A database can find a record in less than a second.
  • SQL was invented in the 1970s.
  • Many banks in Nigeria use PostgreSQL to keep customer money safe.
  • PostgreSQL is free. Anyone can download and use it.
  • Learning databases can help you get a good job.

โ“ Did You Know?

  • Did you know that you can install PostgreSQL for free?
  • Did you know that psql is a command line tool?
  • Did you know that you can create a database in seconds?
  • Did you know that you can create tables with different data types?
  • Did you know that INSERT adds data to a table?
  • Did you know that SELECT finds data in a table?
  • Did you know that UPDATE changes data in a table?
  • Did you know that DELETE removes data from a table?
  • Did you know that you can list all databases and tables?
  • Did you know that you can fix errors and try again?

๐Ÿ” Remember This

  • Install means to put software on a computer.
  • Download means to copy a file from the internet.
  • psql is a command line tool for PostgreSQL.
  • CREATE DATABASE makes a new empty place for your data.
  • Connect means to open a database.
  • CREATE TABLE defines columns and their types.
  • Data types keep your data accurate.
  • INSERT adds data to a table.
  • SELECT finds data in a table.
  • UPDATE changes data in a table.
  • DELETE removes data from a table.
  • Errors are mistakes. You can fix them.

โš ๏ธ Common Mistakes

  1. Forgetting the password you chose during installation.
  2. Typing SQL commands in the wrong case (PostgreSQL is not case-sensitive for commands, but it is for data).
  3. Forgetting to put a semicolon (;) at the end of a command.
  4. Using the wrong data type for a column.
  5. Forgetting to connect to a database before creating a table.
  6. Using the wrong table name.
  7. Forgetting the WHERE clause in UPDATE or DELETE.
  8. Not backing up your data.
  9. Panicking when you see an error. Errors can be fixed.
  10. Not practicing regularly.

โœ… Best Practices

  • Remember your PostgreSQL password.
  • Always end SQL commands with a semicolon (;).
  • Choose the right data type for each column.
  • Connect to a database before creating tables.
  • Use the WHERE clause carefully in UPDATE and DELETE.
  • Back up your data regularly.
  • Practice creating databases and tables.
  • Learn from errors. They help you improve.
  • List your databases and tables to stay organised.
  • Teach others what you learn.

๐Ÿ–ผ๏ธ More ASCII Illustrations, Diagrams, Flowcharts, and Tables

Flowchart: From Installation to Query

   INSTALL POSTGRESQL
         |
         V
   OPEN psql
         |
         V
   CREATE DATABASE
         |
         V
   CONNECT TO DATABASE
         |
         V
   CREATE TABLE
         |
         V
   INSERT DATA
         |
         V
   SELECT DATA
         |
         V
   SEE RESULTS!
  

Timeline: Steps in This Module

   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.
  

Diagram: PostgreSQL Installation

   [ WEBSITE ] --> [ DOWNLOAD ] --> [ INSTALLER ]
         |
         V
   [ RUN INSTALLER ]
         |
         V
   [ CHOOSE PASSWORD ]
         |
         V
   [ CHOOSE PORT 5432 ]
         |
         V
   [ INSTALLATION COMPLETE ]
  

Table: Common SQL Commands

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

Comparison Table: PostgreSQL vs Other Databases

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

๐Ÿ“Œ End-of-Module Summary

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.

โ“ Frequently Asked Questions

  1. What does install mean?
    Install means to put software on a computer so it can be used.
  2. How do I download PostgreSQL?
    Go to the official PostgreSQL website (www.postgresql.org) and click "Download".
  3. How do I install PostgreSQL?
    Download the installer, run it, follow the steps, choose a password and port, and click Finish.
  4. What is psql?
    psql is a command line tool for PostgreSQL. You use it to type SQL commands.
  5. How do I create a database?
    Use the command: CREATE DATABASE myshop;
  6. How do I connect to a database?
    Use the command: \c myshop
  7. How do I create a table?
    Use the command: CREATE TABLE sales (...);
  8. How do I add data?
    Use the command: INSERT INTO sales VALUES (...);
  9. How do I find data?
    Use the command: SELECT * FROM sales;
  10. How do I fix errors?
    Read the error message. Check your spelling and punctuation. Try again.

โœ๏ธ Matching Exercises

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

๐ŸŽญ Scenario-Based Exercises

  1. Scenario: You want to install PostgreSQL. What is the first step?
    Answer: Go to the official PostgreSQL website and download the installer.
  2. Scenario: You want to create a database called "myshop". What command do you use?
    Answer: CREATE DATABASE myshop;
  3. Scenario: You want to connect to the "myshop" database. What command do you use?
    Answer: \c myshop
  4. Scenario: You want to create a table for sales. What command do you use?
    Answer: CREATE TABLE sales (...);
  5. Scenario: You want to add a new sale. What command do you use?
    Answer: INSERT INTO sales VALUES (...);
  6. Scenario: You want to find all sales of rice. What command do you use?
    Answer: SELECT * FROM sales WHERE item = 'Rice';
  7. Scenario: You made a spelling mistake in a command. What should you do?
    Answer: Read the error message. Fix the spelling. Try again.

๐Ÿ‘ฅ Group Activity

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;

๐Ÿง‘ Individual Activity

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;

๐Ÿ› ๏ธ Mini Project

Title: Build a Shop Database
Materials: Computer with PostgreSQL installed.
Steps:

  1. Create a database called "myshop".
  2. Connect to the database.
  3. Create a table called "sales" with columns: id, item, price, quantity, sale_date.
  4. Add at least 5 rows of data.
  5. Run a query to find all sales.
  6. Run a query to find sales of a specific item.
  7. Update the price of one item.
  8. Delete one sale.
  9. List all tables.
  10. Show your database to your class or family.

๐Ÿ“‹ Practical Assignment

Assignment: For one week, practice using PostgreSQL. Keep a diary. Each day, write down:

  • What database you worked with.
  • What table you created or used.
  • What data you added, found, updated, or deleted.
  • What errors you fixed.
  • What you learned.

At the end of the week, write a short report. Share it with your teacher or parent.

๐Ÿ”‘ Key Takeaways

  • Install means to put software on a computer.
  • Download means to copy a file from the internet.
  • psql is a command line tool for PostgreSQL.
  • CREATE DATABASE makes a new empty place for your data.
  • Connect means to open a database.
  • CREATE TABLE defines columns and their types.
  • Data types keep your data accurate.
  • INSERT adds data to a table.
  • SELECT finds data in a table.
  • UPDATE changes data in a table.
  • DELETE removes data from a table.
  • Errors are mistakes. You can fix them.

๐Ÿ’ฌ Classroom Discussion Questions

  1. What does install mean? Give an example.
  2. How do you download PostgreSQL?
  3. How do you install PostgreSQL?
  4. What is psql? How do you use it?
  5. How do you create a database?
  6. How do you connect to a database?
  7. How do you create a table?
  8. What are data types? Give examples.
  9. How do you add data with INSERT?
  10. How do you find data with SELECT?
  11. How do you change data with UPDATE?
  12. How do you remove data with DELETE?
  13. How do you list databases and tables?
  14. What do you do when you see an error?

โžก๏ธ Preparation for Module 3

In Module 3, you will learn more advanced SQL. You will learn about:

  • Joins (combining data from multiple tables).
  • Subqueries (queries inside queries).
  • Views (saved queries).
  • Functions (reusable pieces of code).
  • Indexes (making queries faster).
  • Normalization (organising data efficiently).

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.

๐Ÿ† Get Certified

๐Ÿ”’

Earn this certificate

Every lesson is already free to read. Sign up, finish the lessons, pass the exam (โ‚ฆ2,000 or 20,000 coins), and get a verified certificate with your name on it.

๐ŸŽ“ Sign Up to Get Certified
๐Ÿ› ๏ธ Practice Tools
Hands-on simulators & labs - subscription required.
โ†’
๐ŸŽฏ Internship Tasks
Real-world tasks to build your portfolio - unlock them with a subscription.
โ†’