What is a database?#
A database is an organised collection of data stored so that it can be searched, updated and protected efficiently. Most business data - bills, bank transactions, student records, orders - lives in relational databases.
A relational database stores data in tables (like Excel sheets) that are related to each other through key columns.
| Excel | Database |
|---|---|
| Workbook | Database |
| Sheet | Table |
| Row | Row / record |
| Column | Column / field |
| Anyone can type anything anywhere | Each column has a data type and rules |
| ~1 million rows max, one user editing | Billions of rows, thousands of users at once |
Database = data रखने की एक व्यवस्थित जगह, जहाँ हज़ारों लोग एक साथ लाखों-करोड़ों records पढ़/लिख सकें - जैसे बैंक, IRCTC, Amazon का data।
Relational database में data tables में रहता है (Excel sheets जैसी), और tables आपस में keys से जुड़ी होती हैं।
SQL वह भाषा है जिससे हम database से सवाल पूछते हैं - "मुझे Indore के सारे customers दिखाओ" को SQL में लिखते हैं: SELECT * FROM customers WHERE city = 'Indore';
Keys and relationships#
- Primary key (PK): a column that uniquely identifies each row (
customer_idin customers). - Foreign key (FK): a column that points to a primary key in another table (
customer_idin orders).
This avoids repeating data: the customer's name and city are stored once in customers; each order just stores the customer's ID.
The practice database: shop#
Every SQL editor in this module is connected to this database (an online electronics, furniture and stationery shop):
customers (40 rows) orders (200 rows) order_items (405 rows) products (20 rows)
─────────────────── ───────────────── ────────────────────── ──────────────────
customer_id PK ◄───┐ order_id PK ◄───┐ item_id PK product_id PK
name └──── customer_id FK └────── order_id FK ┌──────► name
city order_date product_id FK ─────┘ category
state status quantity sub_category
segment payment_mode discount price
signup_date cost
employees (15 rows): emp_id PK, name, dept, manager_id (→ emp_id), salary, city, join_date
| Table | Description |
|---|---|
| customers | who buys: name, city, state, segment (Consumer / Corporate / Small Business), signup date |
| products | what we sell: name, category, sub-category, selling price, cost |
| orders | one row per order: customer, date (2024-2025), status (Delivered, Shipped, Cancelled, Returned), payment mode |
| order_items | one row per product in an order: quantity and discount (0 - 0.15) |
| employees | staff with their manager (for self-joins) |
- shop.sql - SQLite script to create the database on your computer
- shop_csv.zip - the same tables as CSV files (for Excel / Power BI)
Your first query#
SELECT * FROM customers;
SELECT- which columns (*= all)FROM- which table;ends the statement
Press Run - try changing customers to products or orders:
Choosing columns and limiting rows#
SQL style rules#
- Keywords are not case-sensitive (
select=SELECT), but writing them in CAPITALS makes queries readable. - Text values go in single quotes:
'Indore'. - Put each clause on its own line for longer queries.
- Comments:
-- single lineor/* multi-line */.
Looking at the structure#
In SQLite you can list tables and columns:
(In MySQL you'd use SHOW TABLES; and DESCRIBE orders;.)
Popular database systems#
| Database | Where you'll meet it |
|---|---|
| MySQL / MariaDB | websites, PHP/Python apps, many Indian companies |
| PostgreSQL | modern startups, analytics, cloud |
| Microsoft SQL Server | enterprises, ERP/finance, Power BI sources |
| Oracle | banks, telecom, large enterprises |
| SQLite | mobile apps, small tools - used on this site |
| Cloud warehouses - BigQuery, Snowflake, Redshift, Azure Synapse | large-scale analytics |
The core SQL you learn here (SELECT, WHERE, GROUP BY, JOIN, CTEs, window functions) works in all of them. Differences are mainly in date and text functions - we'll point them out.
To practise on your own computer, install DB Browser for SQLite (free) and open shop.sql via File → Import → Database from SQL file. For MySQL, install MySQL Community Server + MySQL Workbench.
Summary#
- Relational databases store data in related tables; SQL is the language to query them.
- Primary keys identify rows; foreign keys link tables.
SELECT columns FROM table LIMIT n;is the starting point of every query.- The
shopdatabase (customers, products, orders, order_items, employees) powers every editor in this module.