Introduction to Databases

Sql tutorial · PySpark.in

What Is Data?

Any information that can be stored is called data.

We use data every day in different applications and systems.

Examples of Data

  1. Messages, photos, and videos on WhatsApp
  2. Products, customers, and orders on Amazon
  3. Contact details stored in a phone directory
  4. Student records in schools and colleges
  5. Banking transactions in banking systems

What Is a Database?

A database is an organized collection of data.

Instead of storing information randomly, databases arrange the data properly so it can be:

Real-World Example

Imagine a school storing:

If everything is stored in notebooks, searching becomes difficult.

A database stores all this information in an organized manner.

What Is DBMS?

DBMS (Database Management System)

A DBMS is software used to store, manage, retrieve, and secure data inside a database.

It acts as a bridge between users/applications and the database.

Simple DBMS Architecture

How DBMS Works

Advantages of DBMS

1. Security

DBMS keeps data secure and prevents unauthorized access.

Example

Only bank employees can access customer account details.

2. Ease of Use

DBMS makes it easy to:

3. Durability and Availability

Data remains safe even after system failures and is available whenever needed.

Example

ATM systems work 24/7 because databases are continuously available.

4. Performance

DBMS provides fast access to data even when millions of records are stored.

Example

Searching a product on Amazon takes only a few seconds.

Types of Databases

Databases are classified based on how data is stored and organized.

Databases

├── Relational Database

└── Non-Relational Database
├── Key-Value
├── Document
├── Column Family
└── Graph

Relational Database

In a Relational Database, data is stored in the form of tables.

Each table contains:

Example of Relational Database Table

Student Table

student_id

student_name

course

1

Rahul

SQL

2

Priya

Python

3

Amit

Spark

Features of Relational Databases

Examples of Relational DBMS

Non-Relational Database (NoSQL)

Non-relational databases store data in non-tabular formats.

They are commonly used for:

Types of Non-Relational Databases

1. Key-Value Database

Data is stored as:

Key -> Value

Example

101 -> Rahul
102 -> Priya

Example DBMS

2. Document Database

Stores data in JSON-like documents.

Example

{
"name": "Rahul",
"course": "SQL"
}

Example DBMS

3. Column Family Database

Stores data in columns instead of rows.

Used for handling huge amounts of data.

Example DBMS

4. Graph Database

Stores data in the form of nodes and relationships.

Used in:

Example DBMS

Relational vs Non-Relational Database

Feature

Relational Database

Non-Relational Database

Structure

Tables

Flexible formats

Schema

Fixed

Dynamic

Language

SQL

Different APIs/queries

Best For

Structured data

Unstructured/semi-structured data

Scalability

Vertical scaling

Horizontal scaling

Important Notes

Summary

Topic

Description

Data

Raw information

Database

Organized collection of data

DBMS

Software to manage databases

Relational Database

Data stored in tables

Non-Relational Database

Data stored in flexible formats

RDBMS

DBMS for relational databases

More Sql tutorials

All tutorials · Try the free PySpark compiler · Practice challenges