Skip to content
Hands-on Mentor
ENTR
Back to blog

What is a database? A simple explanation with a real example

What is a database? An organized collection of data in tables that you can search and update with a language like SQL. See how it differs from a spreadsheet.

4 min read

A database is an organized collection of data that a computer can store, search and update quickly. Most databases keep data in tables, where each row is one record and each column is one kind of information. You talk to a database with a language such as SQL.

Think of a university. It needs to know who the students are, which departments exist and which courses each student takes. A database keeps all of that in one place, connected and consistent. This post uses the Northbridge University database in Port Alder as the example.

What does a database look like inside?

A table is a grid. Here is the department table, first three rows:

idnamefaculty
1Computer ProgrammingSchool of Applied Technology
2Software EngineeringFaculty of Engineering
3Industrial EngineeringFaculty of Engineering

And here is the student table, first three rows (some columns left out):

student_nofirst_namelast_namedepartment_id
202303001AnikaPark3
202405001AnikaRivera5
202604001FelixAbara4

The whole database has 7 tables. The two tables above hold 8 departments and 120 students. A third table, enrollment, holds 781 records that say which student took which course offering.

How do tables connect to each other?

Look at the department_id column in student. It holds a department number, not a department name. That number points to the id column of the department table. This link is called a foreign key, and the id it points to is a primary key.

Storing the number instead of the name has a big benefit: the department name exists in only one place. You can read more in [Primary key vs foreign key](/blog/primary-key-vs-foreign-key).

When you want names and numbers together, you join the tables:

SELECT s.first_name, s.last_name, d.name AS department
FROM student AS s
JOIN department AS d ON d.id = s.department_id
ORDER BY s.id
LIMIT 3;
first_namelast_namedepartment
AnikaParkIndustrial Engineering
AnikaRiveraManagement Information Systems
FelixAbaraBusiness Administration

How do you ask a database a question?

You write a query in SQL (Structured Query Language). This one asks which three departments have the most students:

SELECT d.name, COUNT(*) AS students
FROM student AS s
JOIN department AS d ON d.id = s.department_id
GROUP BY d.name
ORDER BY students DESC, d.name
LIMIT 3;
namestudents
Business Administration24
Psychology23
Software Engineering20

You describe what you want, not how to find it. The database decides how to do the work. The same query works if the table has 120 rows or 12 million.

What is the difference between a database and a spreadsheet?

A spreadsheet is a good tool for one table that one person or a small group looks at. A database is built for data that many people and programs use at the same time, and for data that has rules.

SpreadsheetDatabase
StructureA grid where any cell can hold anythingTables with fixed columns and types
RulesFew; you can type text into a number cellConstraints reject bad data (for example, a year of 7)
Connected dataCopy values or use lookup formulasTables link with keys and joins
Many users at oncePossible, but edits can conflictDesigned for it
SizeSlows down with a lot of rowsHandles very large tables
Best forQuick analysis, small lists, budgetsApps, records, anything that must stay consistent

The connection point matters most. Suppose the Software Engineering department changes its name. In a spreadsheet where each student row repeats the department name, you must fix 20 rows and hope you find all of them. In the database, you fix one row:

UPDATE department SET name = 'Software Eng.' WHERE id = 2;

Every student in that department now shows the new name, because they point to the same row. This avoids the duplicate and out-of-date values that spreadsheets collect over time.

What are some everyday examples of databases?

You use databases all day, without seeing them:

  • A school system that stores students, courses and grades.
  • An online store that stores products, customers and orders.
  • A messaging app that stores accounts and conversations.
  • A library catalog that stores books and who borrowed them.

In each one, an app asks the database questions and writes new data back.

Do you need to learn SQL to use a database?

Almost every database that uses tables speaks SQL, so it is the most useful first step. The basics are small: SELECT to read, WHERE to filter, JOIN to combine tables, GROUP BY to summarize. You can learn them by practicing on the Northbridge University database in your browser, with nothing to install.

If you have not met other kinds of databases yet, read [SQL vs NoSQL for beginners](/blog/sql-vs-nosql-for-beginners) next.

What to read next

  • Start the course: [Your first query](/learn/sql/first-query) and [Explore the case](/learn/sql/explore-the-case)
  • Related post: [SQL vs NoSQL for beginners](/blog/sql-vs-nosql-for-beginners)
  • Related post: [Primary key vs foreign key](/blog/primary-key-vs-foreign-key)
  • Browse the whole course: [SQL course](/courses/sql)
  • #database
  • #sql
  • #tables
  • #spreadsheet
All posts