Introduction to Databases
Introduction to Databases
Modern applications depend on data.
When you use a banking app, shopping site, school portal, or social platform, data is constantly being stored and retrieved.
Examples:
- user accounts
- passwords
- products
- payments
- messages
- bookings
- reports
That data must stay available even after the program closes.
Databases are designed for this purpose.
What Is a Database?
A database is an organized system used to store, manage, and retrieve data efficiently.
Instead of keeping information in random files, a database stores data in a structured way.
A good database system allows you to:
- save data permanently
- search quickly
- update safely
- delete records cleanly
- organize relationships
- handle large amounts of data
Why Not Just Use Lists or Text Files?
Python lists, dictionaries, and text files are useful for beginner projects.
Example:
users = [
{"name": "Tom", "age": 25},
{"name": "Maya", "age": 30}
]
This works for small programs.
But as data grows, problems appear:
- hard to search large data
- no built-in relationships
- duplicate data issues
- poor performance
- harder updates
- difficult multi-user access
- weak security
Databases solve these problems.
What Is Structured Data?
Structured data means data organized into clear fields.
Example user data:
- id
- name
- age
Databases store this in tables.
Tables, Rows, and Columns
A table is like a spreadsheet.
Example:
users
+----+------+------------------+-----+
| id | name | email | age |
+----+------+------------------+-----+
| 1 | Tom | tom@mail.com | 25 |
| 2 | Maya | maya@mail.com | 30 |
+----+------+------------------+-----+
Columns
Columns describe what kind of data is stored.
Examples:
- id
- name
- age
Rows
Each row is one complete record.
Example:
Tom, tom@mail.com, 25
What Is SQL?
SQL stands for Structured Query Language.
It is the language used to communicate with relational databases.
With SQL, you can:
- create tables
- insert data
- read data
- update data
- delete data
- filter results
- join tables
- manage permissions
SQL is one of the most important skills in software development.
Example SQL Query
Get all users:
SELECT * FROM users;
Add a user:
INSERT INTO users (name, age)
VALUES ('Tom', 25);
Update a user:
UPDATE users
SET age = 26
WHERE name = 'Tom';
Delete a user:
DELETE FROM users
WHERE name = 'Tom';
What Is CRUD?
CRUD represents the four most common database actions.
Create
Add new data.
INSERT INTO users ...
Read
View data.
SELECT * FROM users;
Update
Change existing data.
UPDATE users ...
Delete
Remove data.
DELETE FROM users ...
Most apps are built around CRUD operations.
What Is a Relational Database?
A relational database stores data in tables that can be related to each other.
Example:
users table
id | name
1 | Tom
2 | Maya
orders table
id | user_id | total
1 | 1 | 50
2 | 2 | 80
The user_id links orders to users.
This relationship is why it is called a relational database.
What Is an RDBMS?
RDBMS stands for Relational Database Management System.
It is the software that manages relational databases.
Examples:
- SQLite
- PostgreSQL
- MySQL
- Oracle
- Microsoft SQL Server
The database is the data itself.
The RDBMS is the software used to manage that data.
Think of it like:
- Data = books
- RDBMS = library system
Popular RDBMS Tools
SQLite
- lightweight
- file-based
- great for beginners
- built into Python
PostgreSQL
- powerful
- advanced features
- excellent for production apps
MySQL
- popular
- widely used in web development
- strong community support
What Is DDL?
DDL stands for Data Definition Language.
DDL commands define or change database structure.
You use DDL to create or modify tables.
Common DDL commands:
CREATEALTERDROPTRUNCATE
Examples
Create table:
CREATE TABLE users (
id INTEGER,
name TEXT,
age INTEGER
);
Add a column:
ALTER TABLE users
ADD COLUMN email TEXT;
Delete table:
DROP TABLE users;
What Is DML?
DML stands for Data Manipulation Language.
DML commands work with the data inside tables.
Common DML commands:
INSERTUPDATEDELETE
Examples
Insert:
INSERT INTO users (name, age)
VALUES ('Tom', 25);
Update:
UPDATE users
SET age = 26
WHERE name = 'Tom';
Delete:
DELETE FROM users
WHERE name = 'Tom';
What About SELECT?
SELECT is often placed in a separate category called DQL.
DQL = Data Query Language.
Used to read data.
SELECT * FROM users;
Some beginners group it under DML, but knowing DQL is helpful.
What Is a Primary Key?
A primary key is a column that uniquely identifies each row.
Example:
id
No two rows should have the same primary key.
This helps databases track records safely.
Why Databases Matter in Python
Python programs often need real storage.
Examples:
- login systems
- inventory systems
- finance trackers
- student portals
- booking apps
- dashboards
Without databases, large apps become difficult to manage.
Code Along
For a school system, write 3 tables you would create.
Example:
- students
- courses
- enrollments
Then write two columns for each.
Mini Challenge
An online store needs:
- users
- products
- orders
Tasks:
- Write one table for each
- Choose a primary key
- Write one relationship between tables
- Write one SQL
SELECTquery example
Example answer:
products(id, name, price)
Real World Use Case
Every major platform uses databases:
- banks
- hospitals
- schools
- e-commerce
- social media
- government systems
Quiz
- What does SQL stand for?
- What is the difference between a database and an RDBMS?
- What does CRUD mean?
- Name two DDL commands.
- Name two DML commands.
- What is a primary key?
- Why are relational databases called relational?
Assignment
Choose one app idea and write:
- 3 tables
- columns for each table
- one primary key per table
- two CRUD actions users would perform
Summary
You learned the foundations of databases, including SQL, CRUD, tables, relational databases, RDBMS, DDL, DML, and why databases are essential in real Python applications.