CodingNic

Databases

Introduction to Databases

Databases 40 min read

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:

python
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
  • email
  • age

Databases store this in tables.


Tables, Rows, and Columns

A table is like a spreadsheet.

Example:

text
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
  • email
  • 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:

sql
SELECT * FROM users;

Add a user:

sql
INSERT INTO users (name, age)
VALUES ('Tom', 25);

Update a user:

sql
UPDATE users
SET age = 26
WHERE name = 'Tom';

Delete a user:

sql
DELETE FROM users
WHERE name = 'Tom';

What Is CRUD?

CRUD represents the four most common database actions.

Create

Add new data.

sql
INSERT INTO users ...

Read

View data.

sql
SELECT * FROM users;

Update

Change existing data.

sql
UPDATE users ...

Delete

Remove data.

sql
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

text
id | name
1  | Tom
2  | Maya

orders table

text
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:

  • CREATE
  • ALTER
  • DROP
  • TRUNCATE

Examples

Create table:

sql
CREATE TABLE users (
    id INTEGER,
    name TEXT,
    age INTEGER
);

Add a column:

sql
ALTER TABLE users
ADD COLUMN email TEXT;

Delete table:

sql
DROP TABLE users;

What Is DML?

DML stands for Data Manipulation Language.

DML commands work with the data inside tables.

Common DML commands:

  • INSERT
  • UPDATE
  • DELETE

Examples

Insert:

sql
INSERT INTO users (name, age)
VALUES ('Tom', 25);

Update:

sql
UPDATE users
SET age = 26
WHERE name = 'Tom';

Delete:

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

sql
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:

text
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:

  1. Write one table for each
  2. Choose a primary key
  3. Write one relationship between tables
  4. Write one SQL SELECT query example

Example answer:

text
products(id, name, price)

Real World Use Case

Every major platform uses databases:

  • banks
  • hospitals
  • schools
  • e-commerce
  • social media
  • government systems

Quiz

  1. What does SQL stand for?
  2. What is the difference between a database and an RDBMS?
  3. What does CRUD mean?
  4. Name two DDL commands.
  5. Name two DML commands.
  6. What is a primary key?
  7. 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.