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:
| id | name | faculty |
|---|---|---|
| 1 | Computer Programming | School of Applied Technology |
| 2 | Software Engineering | Faculty of Engineering |
| 3 | Industrial Engineering | Faculty of Engineering |
And here is the student table, first three rows (some columns left out):
| student_no | first_name | last_name | department_id |
|---|---|---|---|
| 202303001 | Anika | Park | 3 |
| 202405001 | Anika | Rivera | 5 |
| 202604001 | Felix | Abara | 4 |
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_name | last_name | department |
|---|---|---|
| Anika | Park | Industrial Engineering |
| Anika | Rivera | Management Information Systems |
| Felix | Abara | Business 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;
| name | students |
|---|---|
| Business Administration | 24 |
| Psychology | 23 |
| Software Engineering | 20 |
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.
| Spreadsheet | Database | |
|---|---|---|
| Structure | A grid where any cell can hold anything | Tables with fixed columns and types |
| Rules | Few; you can type text into a number cell | Constraints reject bad data (for example, a year of 7) |
| Connected data | Copy values or use lookup formulas | Tables link with keys and joins |
| Many users at once | Possible, but edits can conflict | Designed for it |
| Size | Slows down with a lot of rows | Handles very large tables |
| Best for | Quick analysis, small lists, budgets | Apps, 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