Skip to the content.

SQL > Database Concepts

Database

A database is an organized collection of structured data stored electronically. It enables efficient data storage, retrieval, and manipulation.

Types of Databases

  1. Relational Databases - Stores data in structured tables with predefined schemas and relationships (e.g., MySQL, PostgreSQL, Oracle, SQL Server).
  2. Non-Relational Databases - Stores data in a flexible format without fixed schemas, often used for unstructured or semi-structured data (e.g., MongoDB, Cassandra, Firebase).

Structured vs. Unstructured Data

Relational Databases

Purpose:

A Relational Database (RDBMS) organizes data into structured tables with relationships between them. It ensures data integrity, scalability, and efficient querying using SQL (Structured Query Language).

Real-World Example (College Database):

Students Table:

StudentID Name Major Percentage
1 Ajay Computer Science 85%
2 Balu Mathematics 78%
3 Chaitanya Physics 92%

2. Tables, Rows, Columns

Purpose:

Data in relational databases is stored in tables. Each table consists of columns (fields) and rows (records/tuples).

Key Concepts:

Real-World Example (Employees Database):

An Employees Table for a company:

EmployeeID Name Department Role Salary
1 Anil IT Software Engineer 80000
2 Baskar HR HR Manager 70000
3 Chaitanya Finance Software Engineer 75000

3. Primary and Foreign Keys

Purpose:

Primary Keys (PK) uniquely identify each record, while Foreign Keys (FK) establish relationships between tables.

Key Concepts:

Real-World Example (E-Commerce Database):

Customers Table:

CustomerID Name Email Address
1 Alice alice@email.com New York, USA
2 Bob bob@email.com London, UK
3 Charlie charlie@email.com Sydney, AU
4 David david@email.com Toronto, CA

Products Table:

ProductID ProductName Price Stock
1 Wireless Mouse 25.99 100
2 Mechanical Keyboard 89.99 50
3 USB-C Charger 19.99 200

Orders Table:

OrderID CustomerID TotalAmount OrderDate
101 1 115.98 2024-03-01
102 2 89.99 2024-03-05
103 3 45.98 2024-03-08

Summary

Concept Description
Relational Databases Organize data in structured tables with relationships.
Tables, Rows, and Columns Tables store data, columns define attributes, rows store records.

Next Topic: Data Definition Language (DDL) →