What Is a Database

Updated · 25 min read
easyPostgreSQL 18sqldatabasesbasicsdbms

A database is an organized collection of data that a program can store, search and change quickly and safely. Think of the difference between a messy room and a library. Both hold a lot of things. In the messy room, finding one thing means digging through everything. In the library, every book has a place, a label and an order, so you find it in a minute. A database does for data what a library does for books.

From a pile to a table: organized data can be searched in an instant

You use databases all day without seeing them. Your bank balance, your school grades and the items in an online cart all live in one. When you tap "Pay" and the balance changes a second later, a database did that work: it added a new row to your list of transactions and updated your balance, both at once.

Tap Pay: one new row and one updated balance, saved together

This lesson starts with a real problem, shows how a database organizes data to solve it, and explains the software that does the work. You won't need to write SQL yourself yet. You'll run a prepared query to see how a database answers a real question, and you'll learn to write your own in Your First Query.

In One Minute

  • A database keeps data organized so it can be found, changed and shared safely, by many people at once.
  • A database management system (DBMS) is the software that runs databases. PostgreSQL, MySQL, SQL Server, Oracle and SQLite are examples.
  • Spreadsheets struggle when the data grows, when many people edit at once, or when the data has to follow rules.
  • Relational databases are widely used for business systems. They keep structured data in tables connected through keys. This course teaches them.
  • You ask a relational database questions in SQL: you describe the answer, and the DBMS finds it.
The whole lesson on one card

Data You Need to Keep and Find

Start with a real problem. Three sisters, Srihitha, Advitha and Navika Anamaneni, take courses at a small tutoring program: Java, SQL, JavaScript and Git. The program has to remember who the students are, which courses exist, who signed up for what, and every fee payment. Today that's 3 students, 6 courses, 7 enrollments and 7 payments. Next year it could be hundreds of each.

Every week, someone asks questions like these. Each answer below is real: it comes from the course's Fee Tracker database.

Real questions need facts from more than one place

Look at the bottom of each card: almost every answer needs facts from more than one place. "Who hasn't paid?" needs the list of students and the list of payments. That's why the data has to be organized and connected, not just written down. A database does five jobs to make that possible:

JobWhat it meansIn the tutoring programWithout a database
StoreKeep data safely, for yearsEvery payment is still there at tax timeA lost laptop or a bad save can lose months of records
FindAnswer a question in a moment"Show me Navika's payments"Scrolling, filtering and hoping nothing was missed
ChangeCorrect data in one placeA new fee for SQL Basics is changed onceThe fee is copied on many rows; one copy gets missed
ShareLet many people work at onceThe teacher records enrollments while the accountant records paymentsWithout careful conflict handling, two people's edits can clash or undo each other
ProtectControl who sees and changes whatOnly the accountant can change paymentsAnyone with the file can see and change everything

Data, Information and Tables

Data vs Information

Data is raw values. Information is what those values mean. On its own, this line is data:

text
101, 2, 250.00, 2025-10-30

It's four values, and nobody can tell what they mean. Put them in labeled columns and connect them to the rest of the database, and they become information: "Srihitha paid $250.00 for Java OOP on October 30, 2025." A database stores data with labels, types and connections, so programs can organize it and turn it into meaningful information. The answer is still only as good as the data stored and the question asked: a mistyped amount or a badly worded question gives a wrong answer, however well the database is built.

Table, Row, Column, Value

Four words describe how a relational database holds data. You'll use them in every lesson:

WordMeaningIn the Fee Tracker
TableA collection of one kind of thingpayments: every payment
Row (a record)One of those thingsPayment number 2
Column (a field)One fact that every row hasamount_usd, the amount paid
ValueThe data where one row meets one column250.00

You'll look at these closely in Tables, Rows and Columns.

A Small Puzzle

Before you see how the Fee Tracker is organized, try this. Here is how a beginner might keep the payments: one flat table with everything on every row.

studentemailcourseamountpaid on
Srihithasrihitha.anamaneni@example.comJava OOP250.0010/30/2025
Srihithasrihitha.anamaneni@example.comJava OOP250.0012/03/2025
Navika(none)JavaScript Basics225.0011/14/2025

Now imagine Srihitha gets a new email address, and she has made 20 payments. How many places would you have to update? And what happens if you miss one?

Show the answer

Twenty places, one on every payment row. Miss one, and the table holds two different email addresses for the same person; nobody can tell which is current. The fix is to store Srihitha's email once, in a table of students, and let each payment point to her with a number. That's exactly how the Fee Tracker works, as the next section shows.

How a Database Organizes the Data

A database is the general idea: an organized place to keep data. A relational database is one particular kind, where data is organized into connected tables; you'll meet other kinds at the end of this lesson. This course focuses on the relational kind.

A relational database splits the data into tables, one for each kind of thing. Students go in one table, courses in another. In a well-designed relational table, a key identifies each row uniquely. It can be one column, such as an id, or a combination of columns. Many databases use a number as the key, called an id, and the Fee Tracker does too because numbers are easy to follow. Keys can also be text, such as STUDENT-101, and you'll meet a two-column key in a moment. Then, instead of copying a student's name onto every enrollment, the enrollment stores just the student's id and the course's id:

Each fact is stored once; keys connect the tables, and the line ends show how many rows can match

Read the blue row in enrollments: 102 and 4. The ids lead to the full details: 102 is Advitha and 4 is SQL Basics, so the row means "Advitha takes SQL Basics." Advitha's name and email are written in one place only, in students. If her email changes, it changes once, and every enrollment and payment still points to the right person. That's the answer to the puzzle above.

Now read the purple rows. Payments 2 and 3 both have student 101 and course 2, and both point to the same enrollment: Srihitha paid for Java OOP in two installments.

Notice that an enrollment has no id of its own. The pair of ids, student and course together, is what identifies it, and the database makes sure the same pair can't appear twice. That's the "combination of columns" kind of key. Here is how payments use it:

  • Every payment belongs to an existing student-course enrollment.
  • The database checks both ids together, so a student can't pay for a course they never enrolled in.
  • One enrollment can have several payments, because students may pay in installments.

The marks at the ends of each line in the picture say how many rows can match on each side. Each end combines two of three marks:

SymbolMeaning
Two bars ‖Exactly one
Circle and bar `○`
Bar and crow's foot `<`
Circle and crow's foot ○<Zero or many

The circle means zero is allowed, the bar means one, and the crow's foot (the fork) means many. Together they tell you whether a match is optional or required, and whether one or many rows can match. So line 3 reads: one enrollment has zero or many payments, and each payment belongs to exactly one enrollment. You'll use these marks again in the lessons on keys and relationships.

Here is the complete payments table. These seven rows are the sample payment data used throughout the course; some diagrams and exercises show only selected rows or columns to make one idea easier to see. The picture above, for example, leaves out due_on and method:

SQL▶ Try it
SELECT payment_id, student_id, course_id, amount_usd, paid_on, method
FROM payments
ORDER BY payment_id;
Output
 payment_id | student_id | course_id | amount_usd |  paid_on   | method
------------+------------+-----------+------------+------------+--------
          1 |        101 |         1 |     450.00 | 2025-08-28 | card
          2 |        101 |         2 |     250.00 | 2025-10-30 | card
          3 |        101 |         2 |     250.00 | 2025-12-03 | check
          4 |        101 |         3 |     550.00 | 2025-12-29 | card
          5 |        101 |         4 |     200.00 | 2026-01-05 | NULL
          6 |        103 |         5 |     225.00 | 2025-11-14 | card
          7 |        103 |         5 |     225.00 | 2025-12-19 | check
(7 rows)

The database also enforces the connections. Navika (student 103) isn't enrolled in Java Basics (course 1), so it refuses a payment for it:

SQL▶ Try it
INSERT INTO payments (student_id, course_id, amount_usd, due_on, paid_on, method)
VALUES (103, 1, 450.00, '2026-01-05', '2026-01-05', 'card');
Output
ERROR:  insert or update on table "payments" violates foreign key constraint "payments_student_id_course_id_fkey"
DETAIL:  Key (student_id, course_id)=(103, 1) is not present in table "enrollments".

The message names the rule (a foreign key) and the missing match: there is no enrollment for student 103 in course 1. A spreadsheet would have accepted that row without a word.

You can ask that question right now. Don't worry about the SQL yet; you'll learn every word of it in this course. Press Try it and run it:

SQL▶ Try it
SELECT s.first_name
FROM students AS s
JOIN enrollments AS e ON e.student_id = s.student_id
JOIN courses AS c ON c.course_id = e.course_id
WHERE c.title = 'SQL Basics'
ORDER BY s.first_name;
Output
 first_name
------------
 Advitha
 Srihitha
(2 rows)

The database followed the ids from courses to enrollments to students, and returned two names. The Fee Tracker has one more, small table, cities, which holds each city's state and time zone; it isn't needed here. You'll explore all five tables in detail in The Fee Tracker Database.

Why a Spreadsheet Stops Working

A spreadsheet is a great place to start. Many small businesses keep their first records in one, and for one person with a small list, that's fine. Here is what happens to the same payments as the program grows and more people use the file:

A spreadsheet accepts anything; a database checks every row against its rules
ProblemIn a shared spreadsheetIn a database
Wrong values"fourty" can go in the amount column, and a negative fee looks like any other numberEach column has a type and rules; a row that breaks them is refused with an error
Missing linksA payment can name a student who doesn't exist, or nobody at allTwo rules work together: the student is required (NOT NULL), and it must match a real enrollment (a foreign key)
Copied factsThe course fee sits on every payment row; a change has to find every copyEach fact lives in one place and the rest point to it by id
Many editorsShared spreadsheets can handle simple co-editing, but without reliable conflict handling, edits that touch the same data can clash or undo each otherThe DBMS uses transactions and concurrency control to coordinate everyone's changes and keep the data consistent
Lots of dataOpening, filtering and sorting slow down as rows pile upWith suitable indexes and a well-designed query, the DBMS can find specific rows efficiently, even in tables with millions of records
CrashesA power cut while saving can damage the fileA committed transaction is protected by the DBMS's recovery mechanisms; after a crash, a properly configured system recovers committed changes
AccessWhoever has the file sees and changes everythingEach person gets only the access they need

A spreadsheet and a database solve different problems. A spreadsheet is mainly a tool for working with cells and calculations. A relational database is built to manage structured records, the relationships between them, the rules they must follow, and transactions. Both show rows and columns, and that's where the likeness ends.

One honest detail: storing a fact once is the rule, but sometimes you keep a copy on purpose. A receipt should show the price you actually paid, even if the course fee goes up next year. Good database design decides which copies are deliberate history and which are mistakes waiting to happen. You'll learn how in the database design lessons.

What a Database Management System Does

Applications normally don't edit a database's files directly. A program called a database management system (DBMS) sits between them and the data and safely manages it. Your app sends it a request, written in SQL. The DBMS does the work and sends back the result:

The DBMS checks, plans, runs and protects every request
The DBMSWhat it means for you
Checks permissionsAn app that may only read payments can't change them
Plans the queryIt picks a fast way to find the rows, such as using an index, so you only describe the answer
Runs itIt reads the rows it needs and builds the result table
Keeps the rulesEvery change is checked against the rules (types, required values, links between tables)
Handles many users at onceIt uses concurrency control to coordinate people working at the same moment. Sometimes one change waits for another, or is refused and has to be tried again, but changes don't silently overwrite each other
Protects finished changesChanges are grouped into transactions: all of a transaction is saved, or none of it is, and a committed one survives a crash

The database and the DBMS are two different things. The database is the data: the Fee Tracker's tables and rows. PostgreSQL is the DBMS: the software that manages it. One PostgreSQL server can hold many databases side by side, such as feetracker for this course and another for a shop. In everyday talk people say "the database" for both, and that's fine once you know the difference.

Kinds of Databases

Different questions need data in different shapes. That's why several kinds of databases exist. Here is the same tutoring program stored four ways:

Four shapes for the same facts
KindStores data asChoose it whenExamples
RelationalTables of rows and columns, connected by idsThe data has a clear structure and many connections, and it must stay correct: payments, orders, accounts, studentsPostgreSQL, MySQL, SQL Server, Oracle, SQLite
DocumentSelf-contained records, usually JSONEach record's shape can differ, and you usually read one whole record at a time: a product catalog where a laptop and a T-shirt have different detailsMongoDB, Couchbase
Key-valueA value saved under a key, like a dictionaryThe main job is "give me the value for this key," as fast as possible: login sessions, caches, settingsRedis, Amazon DynamoDB
GraphPoints and the links between themThe connections are the question: friends of friends, the shortest route, who mentors whomNeo4j

These groups aren't strict boxes. Redis and DynamoDB can do more than plain key-value lookups, and PostgreSQL can store JSON documents inside a table. But the shapes explain why each kind exists. Every kind can protect its data; they just do it in different ways. Relational databases are widely used for business systems where structured records, relationships, transactions and data integrity matter, and they're the foundation of this course.

Where You Already Use Databases

You use relational databases many times a day without seeing them:

Behind each of these is a table of rows
  • Paying with a card: the bank keeps your current balance and the list of every transaction. A payment can add a transaction row and update the balance in one database transaction. Both changes are saved together, or neither is, so the database is never left with only half of the payment done.
  • School: students, classes, grades and attendance are separate tables that point to each other by id.
  • Shopping: products, carts, orders and shipments, with stock counts that a rule keeps from going below zero.
  • Your phone: many mobile apps use SQLite to keep data on the device itself, such as saved settings, cached information or offline content.

Check Yourself

Before the next lesson, explain this in your own words, out loud or on paper:

A tutoring center has 100 students, 6 courses and 500 payments. Why would keeping everything in one spreadsheet become difficult? How would separating students, courses, enrollments and payments help?

Compare with a possible answer

In one spreadsheet, every payment row would repeat the student's name and email and the course's title and fee. A student who paid 10 times has their email copied 10 times, so one change means 10 edits, and a missed one leaves two different emails. Nothing stops a typo, a negative amount, or a payment for a student who doesn't exist. And with several people editing, changes can clash. Separate tables store each student and each course once. Enrollments connect a student to a course, payments point to an enrollment, and the database checks every link and every value before it accepts a row.

Common Mistakes

Thinking a database is just a big spreadsheet. Both show rows and columns, but a database enforces rules, handles many users at once, keeps finished changes after a crash, and connects tables by ids. That's why its structure is stricter.

Mixing up the database and the DBMS. The database is the data. PostgreSQL or MySQL is the software that manages it, and one server can hold many databases.

Thinking every repeated value is a mistake. Copying a student's name onto every payment row is a mistake, because the copies drift apart. Keeping the price a customer actually paid on their receipt is deliberate history. The question is always: if the original changes, should this copy change too?

Thinking you need to install something before you can learn. You don't. Every example in this course has a Try it button that runs a real PostgreSQL database in your browser.

Practice

Challenge: Before the Fee Tracker, the tutoring program kept payments in a shared spreadsheet. Here are four of its rows. They are the real payments 2, 3, 6 and 7 from the payments table above, with the course fee copied onto each row the way spreadsheets often do it. One fact to know: the JavaScript Basics fee has always been $450.00; it never changed.

payment_idstudentcoursecourse_feeamountpaid_on
2SrihithaJava OOP500.00250.0010/30/2025
3SrihithaJava OOP500.00250.0012/03/2025
6NavikaJavaScript Basics450.00225.0011/14/2025
7NavikaJavaScript Basics400.00225.0012/19/2025

Answer three questions: (1) Payments 2 and 3 look almost the same. Are they a mistake? How can you tell? (2) What is wrong with payments 6 and 7, and how did it happen? (3) How do the Fee Tracker's tables prevent it? And what would change if the fee had really gone down to $400.00 in December?

Show a possible answer

(1) Not a mistake. They have different payment_id values and different dates, so they are two real installments: Srihitha paid for Java OOP in two parts. Without an id and a date, nobody could tell an installment from an accidental duplicate. (2) A copying mistake. The fee never changed, so the 400.00 on payment 7 is simply wrong: someone mistyped or edited one copy, and nothing checked it against the others. (3) Store the current fee once. In the Fee Tracker, the fee lives only in courses, and each payment stores just the course_id, so there's one copy and it can't disagree with itself. If the fee really had changed, the database would need to keep the price agreed when each student enrolled. That agreed price belongs to the enrollment, not to any one installment, and each payment would still store the amount actually paid. Changing the current course fee shouldn't rewrite an existing student's agreement, so the agreed price would be stored on purpose as history. The Fee Tracker doesn't need it yet, because no fee has changed; you'll design it properly in the lessons on normalization and historical data. Telling a deliberate copy from a careless one is the heart of database design.

Quick check: What is a database

3 questions
1The teacher and the accountant both update the tutoring program's records at the same moment. What does a DBMS do that a shared spreadsheet file doesn't?
2An enrollment row stores student_id 102 and course_id 4. Why store the ids instead of the student's name and the course title?
3A shop needs to show a customer's past orders, keep stock counts correct, and never accept an order for a product that doesn't exist. Which kind of database fits best?

Key Takeaways

TermMeaning
DatabaseAn organized collection of data that programs can store, find and change
DBMSThe software that manages databases, such as PostgreSQL
TableOne kind of thing (students, payments), stored as rows and columns
KeyA value, or a combination of values, that identifies one row and lets other tables point to it
IdA key that is a number, like student_id 101; the Fee Tracker uses these
TransactionA group of changes saved all together or not at all
Fee TrackerThe tutoring program's database, used in every lesson of this course

Next: you've seen what a database does and how its tables connect. In What Is SQL, you'll learn the language that asks the questions: what a statement looks like, the four jobs SQL does, and why you describe the answer instead of the steps.

Was this tutorial helpful?

Lesson 1 of 115