Welcome to Module Three!
In the previous module, you learned how to use Microsoft Excel and Google Sheets to organise information in rows and columns.
But imagine that a bank has information about five million customers. Can you imagine trying to manage all that information using a small spreadsheet?
It would be difficult!
This is why organisations use databases.
A database helps people store, organise, manage, and retrieve large amounts of information using a computer.
In this module, you will learn what databases are, how they work, and how SQL helps people find information stored inside them.
A database is an organised collection of information stored electronically so that it can be accessed, managed, and updated.
Think of a database as a digital filing cabinet.
Instead of keeping hundreds of paper files inside a cabinet, an organisation can store information in a computer database.
Imagine that your school has 2,000 students.
The school needs to store information such as:
A database can store all these records and help authorised school staff find the information they need.
Many databases organise information using tables.
A database table looks similar to a spreadsheet because it contains rows and columns.
| Student ID | Student Name | Class | Age |
|---|---|---|---|
| 101 | John | JSS 1 | 12 |
| 102 | Mary | JSS 2 | 13 |
| 103 | David | JSS 1 | 12 |
| 104 | Sarah | JSS 3 | 14 |
Let's understand the different parts:
A Database Management System, also called a DBMS, is software that helps people create, manage, and use databases.
Think of a DBMS as a manager that helps organise information inside a digital filing cabinet.
When you register on a website, the website may save your name, email address, and other information in a database.
The website's database management system helps store and retrieve that information when needed.
SQL stands for Structured Query Language.
SQL is a language used to communicate with relational databases.
Imagine that a database contains information about 10,000 students. You want to find only the students in JSS 2.
Instead of searching through every record manually, you can use SQL to request the information.
This request is called a query.
SQL has different commands. Each command performs a particular task.
The SELECT command is used to retrieve information from a database.
Example:
SELECT * FROM Students;
This command asks the database to display all columns and records from the Students table.
The WHERE condition helps you find records that match a particular requirement.
Example:
SELECT * FROM Students
WHERE Class = 'JSS 2';
This query displays students whose class is JSS 2.
The INSERT command is used to add new information to a database table.
Example:
INSERT INTO Students
(StudentID, StudentName, Class, Age)
VALUES
(105, 'Peter', 'JSS 1', 12);
This command adds a new student record.
The UPDATE command changes existing information in a database.
Example:
UPDATE Students
SET Class = 'JSS 2'
WHERE StudentID = 101;
This changes the class of the student whose ID is 101.
The DELETE command removes records from a database table.
Example:
DELETE FROM Students
WHERE StudentID = 105;
This removes the record belonging to student ID 105.
Important: Always check your WHERE condition before running UPDATE or DELETE commands. Without a suitable condition, you may change or remove more records than intended. Practise these commands on sample data first.
A primary key is a column or combination of columns used to uniquely identify each record in a database table.
Think about your school registration number. Two students should not have the same registration number.
This makes the registration number useful as a primary key.
| Student ID | Name | Class |
|---|---|---|
| 101 | John | JSS 1 |
| 102 | Mary | JSS 2 |
| 103 | David | JSS 1 |
Each student has a different Student ID. This makes it possible to identify each student correctly.
A foreign key is a column in one database table that refers to a key in another table.
It helps connect related information stored in different tables.
Imagine that a school has two tables.
| Student ID | Student Name |
|---|---|
| 101 | John |
| 102 | Mary |
| Exam ID | Student ID | Score |
|---|---|---|
| 1 | 101 | 85 |
| 2 | 102 | 92 |
The Student ID in the Examinations table can refer to the Student ID in the Students table.
This relationship helps the school connect examination scores to the correct students.
Now that you understand databases and SQL, let's look at two popular database systems.
MySQL is a database management system used by many websites and applications.
It helps developers store information such as customer accounts, product details, and orders.
PostgreSQL is another database management system. It is known for its powerful features and ability to manage complex data.
Data analysts often use SQL to find useful information inside databases.
For example, a supermarket wants to know which products generated the highest sales.
The analyst can use SQL to retrieve product sales records and calculate totals.
Here is another example:
SELECT ProductName, QuantitySold
FROM Sales;
This query retrieves the product names and quantities sold from the Sales table.
SQL can also be used with other tools:
This is why SQL is an important skill for data analysts.
Imagine that you are helping your school organise student information.
Create a table called Students with the following columns:
Enter the following sample records:
| StudentID | StudentName | Class | Age |
|---|---|---|---|
| 101 | John | JSS 1 | 12 |
| 102 | Mary | JSS 2 | 13 |
| 103 | David | JSS 1 | 12 |
| 104 | Sarah | JSS 3 | 14 |
Practise writing the following SQL commands:
Challenge: Explain why StudentID is a better identifier than StudentName for this table.
Answer the following questions to test what you have learned.
Well done! You have completed Module Three of Data Analysis Tools Overview.
In this module, you learned:
In the next module, you will discover how programming languages such as Python and R help data analysts work with information. You will also explore tools such as Jupyter Notebook, Pandas, and NumPy.
Keep practising. Every new skill brings you closer to becoming a confident data analyst!
CRMNuggets โ Learn. Practice. Get Certified.