Beginner · Databases and SQL basics · topic 16 of 54 · 20 min
What is a database?
Explanation
Why not just a file or an array?
An array in your code lives in memory (RAM). When the server restarts, it is gone. A plain file survives restarts, but if two users save at the same moment the file can break, and finding one order among ten lakh means reading the whole file.
A database is a program built only for storing data. It keeps data safe on disk, lets thousands of users read and write at the same time without breaking anything, and finds rows quickly even in huge tables.
Tables, rows and columns
- A table holds one kind of thing: students, orders or trains.
- A column is one detail that every row has, like name or fare. Each column has a data type.
- A row is one item: one student, one order, one train.
- A primary key is a column whose value is unique for every row, like a roll number or a PNR. It lets you point to exactly one row.
| Data type (SQLite / PostgreSQL) | Holds | Example |
|---|---|---|
| INTEGER | Whole numbers | 12951, 3100 |
| REAL / NUMERIC | Numbers with decimals | 4.5, 199.99 |
| TEXT | Words and sentences | 'Mumbai Rajdhani' |
| DATE / TEXT | Dates (SQLite stores them as text) | '2026-10-19' |
| BOOLEAN / INTEGER | Yes or no (SQLite uses 1 and 0) | true, 1 |
SQL: the language of databases
SQL (Structured Query Language, said "S-Q-L" or "sequel") is the language you use to talk to a relational database. A relational database stores data in tables that can be linked to each other. CREATE TABLE makes a new table, INSERT adds rows and SELECT reads them.
CREATE TABLE trains (
number INTEGER PRIMARY KEY,
name TEXT NOT NULL,
from_city TEXT,
to_city TEXT,
fare INTEGER
);
INSERT INTO trains (number, name, from_city, to_city, fare)
VALUES (12951, 'Mumbai Rajdhani', 'Mumbai', 'New Delhi', 3100);
SELECT * FROM trains;SQL vs NoSQL in one paragraph: SQL databases (PostgreSQL, MySQL, SQLite) store data in tables with fixed columns and are the safe default for most apps, especially anything with money. NoSQL databases (like MongoDB) store flexible documents, similar to JSON, and suit data whose shape changes often. You will meet NoSQL in a later module.
Popular choices: PostgreSQL (powerful, free, the most common pick for new backends), MySQL (very widely used, for example by WordPress), and SQLite (a whole database in one file, used inside phones and for learning). The tasks on this site run SQLite inside your browser.
Watch the lesson
What is a database? · 1/6
Every serious app keeps its data in a database. Today we see why, and how data is laid out.
Prefer a video by a teacher? Find free videos on “what is a database sql tables rows columns for beginners” on YouTube ↗
In real life: Train seats on a booking site
A train booking site keeps trains, coaches, seats, passengers and bookings in a database. When two people try to book the last seat in the same coach at the same second, the database makes sure only one booking succeeds. When you check your PNR, the server runs a query like SELECT * FROM bookings WHERE pnr = '4521378901' and gets your row out of crores of rows in milliseconds, thanks to the primary key.
Practice (0/3 done)
The table trains has the columns number, name, from_city, to_city and fare. Write a query that shows every column of every train.
The database is empty. Write three statements, one after another: 1) CREATE TABLE books with columns id (INTEGER PRIMARY KEY), title (TEXT NOT NULL) and price (INTEGER). 2) INSERT two rows: (1, 'Wings of Fire', 299) and (2, 'Godan', 199). 3) SELECT * FROM books. The checker looks at the result of your LAST statement.
A kirana shop wants a billing app. Design the products table on paper: list each column with its data type, choose the primary key, and say which columns must be NOT NULL. Then write the CREATE TABLE statement.
Quick quiz
Read more (free)
Pass the quiz (60% or more) or mark this topic as done when you are ready.
Your progress is saved on this device only.