Loading
Types of Database-tutorial
Now that you know how a database is structured with tables, rows, and columns
let us explore the two major types of databases you will encounter in the real world:

  • Relational Databases (SQL-based)
  • Non-Relational Databases (NoSQL-based)
Both store data but in different ways and for different needs.



1. Relational Databases (SQL Databases)

Relational databases organize data into tables (rows and columns).
Each table stores specific information and tables are connected through relationships.

Think of it like a well-structured Excel sheet each sheet (table) has its own data, and you can link them using a common column.


Key Concepts

TermMeaning
TableCollection of data (like a spreadsheet)
Row (Record)Single entry of data
Column (Field)Attribute or property of data
Primary KeyUnique ID for each record
Foreign KeyA link between two tables



Example: Online Store Database

Let us say you own an e-commerce store, You have two tables Customers and Orders.

Table: Customers

CustomerIDNameCity
1Amit KumarDelhi
2Rohit DasMumbai


Table: Orders

OrderIDCustomerIDProductPrice
1011Laptop50,000
1022Headphones2,000

Here,

  • The Customers table stores all customer details.
  • The Orders table stores order information.
  • The CustomerID column in both tables helps us connect which customer placed which order even if we don’t know the exact SQL command yet.
Later, when you learn SQL queries, you’ll see how we can combine this data to show results together.

Foreign Key

You can simply say:

Here, the customerID in the Orders table refers to the Customer in the Customers table.
This connection between tables is called a relationship, and you will learn more about it when we study Foreign Keys later.




Example

SELECT Customers.Name, Orders.Product, Orders.Price
FROM Customers
JOIN Orders
ON Customers.CustomerID = Orders.CustomerID;


Output

NameProductPrice
Amit KumarLaptop50,000
Rohit DasHeadphones2,000


Examples of Relational Databases

  • MySQL
  • PostgreSQL
  • Oracle Database
  • Microsoft SQL Server



2. Non-Relational Databases (NoSQL Databases)

Not all data fits perfectly into tables.
Sometimes we have unstructured or semi-structured data like images, comments, or user preferences.
That is where Non-relational (NoSQL) databases come in.

They store data in flexible forms such as:

  • Documents (JSON, XML)
  • Key-Value pairs
  • Graphs
  • Wide Columns
There are no fixed schemas each record can look different.



Real Life Analogy

Imagine a digital diary where every page (document) may have different details.
Unlike a relational table, there is no strict rule that every page must have the same columns.



Example: Storing Customer Data in MongoDB (Document Format)

{
  "CustomerID": 1,
  "Name": "Amit Kumar",
  "City": "Delhi",
  "Orders": [
    { "Product": "Laptop", "Price": 50000 },
    { "Product": "Mouse", "Price": 1200 }
  ]
}

Here:

  • Everything about Amit her details and orders is stored together in one document.
  • This makes retrieval fast and flexible.


Examples of Non-Relational Databases

  • MongoDB (Document-based)
  • Redis (Key-Value store)
  • Cassandra (Wide Column)
  • Neo4j (Graph-based)
  • Firebase (Cloud-based)



Difference Between SQL and NoSQL

FeatureRelational (SQL)Non-Relational (NoSQL)
StructureTables (rows & columns)Documents, key-value, graphs
SchemaFixedFlexible
LanguageSQLJSON / APIs
Best ForStructured data, transactionsUnstructured or big data
ExamplesMySQL, PostgreSQLMongoDB, Firebas



Two Minute Drill

  • Databases are of two main types : Relational (SQL) and Non-Relational (NoSQL).
  • Relational = Tables + Keys + Relationships.
  • Non-relational = Documents + Flexibility + Scalability.
  • NoSQL uses nested documents or references.
  • Both are essential in modern development often used together.