Skip to content

Beginner: asking questions · Databases and the relational model · topic 1 of 62 · 25 min

What a database is

Explanation

Data is facts, like a name or a price. A database is an organised store of data, and a DBMS (database management system) is the software that keeps it safe and answers questions about it. Apps like IRCTC, banks and school portals all keep their data in a database and talk to it in SQL.

Data, database and DBMS

Data means facts: a student's name, the price of a pressure cooker, the date of an order. On their own, facts are not very useful. They become useful when they are organised so you can find them, check them and change them.

A database is an organised collection of data, stored so that a computer can find any part of it quickly. A DBMS, short for database management system, is the software that looks after a database. It stores the data on disk, answers questions about it, stops two people from breaking each other's changes, and controls who may see what.

MySQL, PostgreSQL, SQLite, Oracle and Microsoft SQL Server are all DBMSs. In daily talk people say "the database" for both the data and the software, and that is fine. Just remember that the data and the program that manages it are two different things.

Think of it like this: Think of a big college library. The books are the data. The shelves with numbered racks and the catalogue are the database: an organised way to keep the books. The librarian is the DBMS: you ask "do you have a book by R. K. Narayan?", and the librarian knows where to look, records who borrowed what, and does not let two students take the same copy.

Why not just use Excel?

A spreadsheet is great for one person and a few thousand rows. A real app needs much more, and a database is built for exactly those needs.

NeedSpreadsheetDatabase
Many users at onceTwo people editing one file can overwrite each otherThousands of users can read and write at the same time
SafetyA crash in the middle of saving can damage the fileA change is saved fully or not at all, even after a power cut
SizeAn Excel sheet stops at 1,048,576 rowsTables with crores of rows are normal
RulesAnyone can type "abc" in a price cellRules (constraints) reject wrong data before it is saved
QuestionsFilters and formulas, done by handOne SQL query, run by a program, gives the answer in milliseconds

Relational and NoSQL databases

A relational database keeps data in tables of rows and columns, and links tables to each other through shared values called keys. You talk to it in SQL (Structured Query Language). PostgreSQL, MySQL, SQLite, Oracle and SQL Server are relational. NoSQL databases store data in other shapes: documents that look like JSON (MongoDB), key and value pairs (Redis), or wide columns (Cassandra). They suit data whose shape changes often or that must spread over many servers. Relational databases are the safe default for most apps, especially anything with money, and this course focuses on them. Module 11 compares NoSQL in more detail.

Where the database sits in an app

You never talk to a big app's database directly. Your phone or browser talks to the app's server, and the server talks to the database in SQL.

output
Your phone / browser  -->  App server (Java, Python, Node.js...)  -->  Database (PostgreSQL, MySQL...)
      "Book a seat"            runs SQL: find a free seat, save booking       stores trains, seats, bookings
The three layers of a typical app. Only the server sends SQL to the database.
  • A train booking site like IRCTC keeps trains, coaches, seats, passengers and bookings in tables. When you check a PNR, the server runs a query that finds one booking among crores.
  • A bank keeps customers, accounts and every transaction. A transfer must take money from one account and add it to another together, or not at all.
  • A school portal keeps students, classes, marks and fees, so teachers can enter marks and parents can see report cards.

Your first query

In this course you write SQL right here in the browser. The site runs SQLite, a small but complete database engine, inside the page. The practice table students holds eight college students. The query below reads all of it.

sql
SELECT * FROM students;
SELECT means "show me", the star * means "all columns", and FROM students names the table. It returns all 8 rows, from Asha Verma (Pune, BCA, 76 marks) to Karan Mehta (Mumbai, BSc, 79 marks).

Your roadmap for this course

Weeks (1 hour a day)LevelWhat you learn
Weeks 1–4BeginnerTables and keys, SELECT, filters, sorting, functions, GROUP BY
Weeks 5–9IntermediateJoins, subqueries, CTEs, window functions, changing data, transactions
Weeks 10–13ExpertSchema design, indexes, query plans, views, engines, NoSQL, interview practice

Common mistakes

  • Thinking SELECT changes data. SELECT only reads; it never adds, edits or deletes anything. You can run it as often as you like.
  • Misspelling a table name. SELECT * FROM student gives "no such table: student". Check the exact name; here it is students.
  • Using a shared spreadsheet as the "database" of a growing business. It works for a month, then two people overwrite each other. Move to a real database early.
  • Expecting SQL to be one product. SQL is a language; MySQL, PostgreSQL and SQLite are products that speak it with small differences.

Need help?

Stuck on a word or an idea? Search this course, or every course, and jump straight to the explanation or a worked question.

Try:

Watch the lesson

What a database is · 1/7

What a database is

Welcome to SQL and Databases. In this first lesson we see what a database is and why almost every app uses one.

Prefer a video by a teacher? Find free videos on “what is a database and DBMS for beginners relational database explained” on YouTube ↗

In real life: A kirana shop goes online

A neighbourhood grocery shop starts taking orders on WhatsApp and writes them in a notebook. Soon there are 80 orders a day, and two staff members write in the same notebook. They move to a small app backed by a database: customers, products and orders are tables, stock goes down automatically when an order is saved, and the owner can ask "what sold most this week?" with one query instead of an evening of counting.

sql
-- The practice SHOP database of this course looks like that shop:
SELECT * FROM customers;
Returns 6 customers, from Asha Verma (Pune) to Arjun Reddy (Hyderabad).

Practice (0/3 done)

Task 1 · Code · SQL

Your first query. The table students has the columns id, name, city, course, marks and fees_paid. Show every column of every row.

Task 2 · Code · SQL

The SHOP database has a table named products. Show every column of every product.

Task 3 · Practice

Pick three apps you used today (for example a UPI app, a food delivery app and your college portal). For each one, write down three tables its database probably has, and two columns of each table.

Quick quiz

Question 1

1.What is a DBMS?

Question 2

2.A shop has 40 staff updating stock at the same time. Why is a database better than one shared spreadsheet?

Question 3

3.In a typical app, who sends SQL to the database?

Question 4

4.What does SELECT * FROM students; do?

Question 5

5.Which of these is a relational database?

Read more (free)

Open a question to see the answer and why. The first ones are this topic's own quiz, so try the quiz above before you peek.

What is a DBMS?

Answer: The software that stores, protects and answers questions about a database

A database management system, like PostgreSQL or MySQL, is the program that looks after the data.

A shop has 40 staff updating stock at the same time. Why is a database better than one shared spreadsheet?

Answer: A database lets many users write at once without overwriting each other

Handling many users at once safely is one of the main jobs of a DBMS.

In a typical app, who sends SQL to the database?

Answer: The app server

The phone talks to the server; the server runs SQL against the database.

What does SELECT * FROM students; do?

Answer: Shows every column of every row of students

SELECT reads data, and * means all columns.

Which of these is a relational database?

Answer: PostgreSQL

PostgreSQL stores data in tables and uses SQL. MongoDB and Redis are NoSQL.

Why do apps store users in a database and not in an array in the code?Related

Answer: An array is lost when the server restarts

An array lives in memory and disappears on restart. A database keeps data safely on disk.

From What is a database?

Which database type is Redis?Related

Answer: Key-value

Redis stores values under keys in memory, which makes it great for caches, sessions and counters.

From NoSQL and MongoDB

Which need is the best fit for a wide-column store such as Cassandra?Related

Answer: Billions of sensor readings written every second across many servers

Wide-column stores shine at huge, write-heavy, partitioned data.

From NoSQL: documents, key-value, wide-column and graph

A new app needs users, orders and payments. What is the sensible default?Related

Answer: A relational database such as PostgreSQL or MySQL

Relational databases give transactions, constraints and joins; add others later for specific needs.

From Choosing a database, and keeping it safe

Pass the quiz (60% or more) or mark this topic as done when you are ready.

Your progress is saved on this device only.

Next steps

  1. 4 more topics in “Databases and the relational model” before its exam: Tables, rows, columns and data types, Keys and relationships, CREATE TABLE and constraints, The SQL language and your tools.
  2. Module 1 exam: Databases and the relational model · 15 questions · 25 min, without help. 5 topics of this module still to finish first.
  3. Then the next module, SELECT: filtering and sorting. 62 topics left in the course before the final exam.