Beginner: asking questions · Databases and the relational model · topic 1 of 62 · 25 min
What a database is
Explanation
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.
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.
| Need | Spreadsheet | Database |
|---|---|---|
| Many users at once | Two people editing one file can overwrite each other | Thousands of users can read and write at the same time |
| Safety | A crash in the middle of saving can damage the file | A change is saved fully or not at all, even after a power cut |
| Size | An Excel sheet stops at 1,048,576 rows | Tables with crores of rows are normal |
| Rules | Anyone can type "abc" in a price cell | Rules (constraints) reject wrong data before it is saved |
| Questions | Filters and formulas, done by hand | One 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.
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- 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.
SELECT * FROM students;Your roadmap for this course
| Weeks (1 hour a day) | Level | What you learn |
|---|---|---|
| Weeks 1–4 | Beginner | Tables and keys, SELECT, filters, sorting, functions, GROUP BY |
| Weeks 5–9 | Intermediate | Joins, subqueries, CTEs, window functions, changing data, transactions |
| Weeks 10–13 | Expert | Schema 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
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.
-- The practice SHOP database of this course looks like that shop:
SELECT * FROM customers;Practice (0/3 done)
Your first query. The table students has the columns id, name, city, course, marks and fees_paid. Show every column of every row.
The SHOP database has a table named products. Show every column of every product.
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
Read more (free)
Related help
Related topics
- Tables, rows, columns and data typesDatabases and the relational model · same module
- Keys and relationshipsDatabases and the relational model · same module
- CREATE TABLE and constraintsDatabases and the relational model · same module
- What is a database?Backend Development · Databases and SQL basics
- NoSQL and MongoDBBackend Development · NoSQL, ORMs and data features
- NoSQL: documents, key-value, wide-column and graphProcedures, triggers, SQL engines and NoSQL
Questions people ask about this
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.
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.
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
- 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.
- Module 1 exam: Databases and the relational model · 15 questions · 25 min, without help. 5 topics of this module still to finish first.
- Then the next module, SELECT: filtering and sorting. 62 topics left in the course before the final exam.