What is a database?
What is a database?
Think of a database as a very well organised, very fast filing system. Instead of paper folders, data sits in a structure the computer understands, so it can answer questions like "which customers in Leeds ordered in March?" in a fraction of a second, even with millions of records. Most databases also let many people and programs use the data at once without getting in each other's way.
Tables, records and fields
The most common kind of database stores data in tables, a bit like spreadsheets. Here is a small customers table for an online shop:
| customer_id | name | city | |
|---|---|---|---|
| 1 | Amira Khan | amira@example.com | Leeds |
| 2 | Tom Ellis | tom@example.com | Bristol |
| 3 | Grace Obi | grace@example.com | Leeds |
- Table: all the data about one kind of thing, here customers.
- Record (row): one customer, such as Tom Ellis.
- Field (column): one piece of information stored for every record, such as email. Each field has a data type, such as text, a whole number or a date.
- Primary key: a field that never repeats, so it picks out exactly one record. Here it is customer_id, because two customers could share a name.
These are the terms the AQA GCSE Computer Science specification expects: table, record, field, data type, primary key and foreign key.
What is database software?
The data on its own is just bytes in files. Database software, properly called a database management system (DBMS), is the program that stores those files, answers questions about them and keeps them safe. When an app saves your order, it doesn't write to the files itself; it sends a request to the DBMS. The DBMS:
- finds data quickly using indexes, like the index at the back of a book;
- lets many users read and write at the same time without mixing up their changes;
- checks rules, such as "every order must belong to a real customer";
- controls who can see or change what;
- makes backups and recovers from crashes without losing finished work.
| Database software | Type | Typical use |
|---|---|---|
| MySQL | Relational (SQL) | Websites and web apps |
| PostgreSQL | Relational (SQL) | Web apps, data analysis, mapping |
| Microsoft SQL Server | Relational (SQL) | Business systems |
| Oracle Database | Relational (SQL) | Large companies and banks |
| SQLite | Relational (SQL), stored in a single file | Phones, browsers and apps on your device |
| Microsoft Access | Relational, desktop | Small office databases with forms |
| MongoDB | Document (NoSQL) | Apps with flexible, changing data |
| Redis | Key value (NoSQL) | Very fast caching and sessions |
You probably use SQLite every day without knowing it. Its developers say it is "likely used more than all other database engines combined" and estimate that over one trillion SQLite databases are in active use, according to sqlite.org.
Database vs spreadsheet vs files
A spreadsheet also stores rows and columns, so why use a database? For a small list one person edits, a spreadsheet is fine. Databases win as data grows and more people use it:
| Spreadsheet or plain files | Database | |
|---|---|---|
| Size | Slows down with large amounts of data | Handles millions of records quickly |
| Many users at once | Risk of overwriting each other's changes | Designed for it |
| Rules on the data | Easy to type anything anywhere | Data types and rules are enforced |
| Linking data | Copies of the same data drift apart | Related tables linked by keys, each fact stored once |
| Used by apps | Awkward | Apps talk to it directly through queries |
Storing each fact once matters. If a customer's address is copied into every order, changing it means finding every copy, and missing one leaves the data contradicting itself. AQA calls these problems data redundancy (needless copies) and data inconsistency (copies that disagree). Try it: this question describes a job and asks whether a database or something simpler is the right tool.
Pick the best storage method for each scenario.
Press Mark to have your answer marked in the Databases course.
How do you get data out of a database?
Relational databases use SQL (Structured Query Language). You describe what you want, and the DBMS works out how to fetch it. This query asks for the names and emails of customers in Leeds, sorted by name:
SELECT name, email
FROM customers
WHERE city = 'Leeds'
ORDER BY name;| name | |
|---|---|
| Amira Khan | amira@example.com |
| Grace Obi | grace@example.com |
Three more commands cover changing data: INSERT adds a record, UPDATE changes one, and DELETE removes one. Together with reading, these four jobs are often called CRUD: create, read, update, delete. The Databases course has you writing these queries yourself.
Types of databases
| Type | How it stores data | Good for |
|---|---|---|
| Relational (SQL) | Tables linked by keys | Most business and web data: customers, orders, bookings |
| Document (NoSQL) | Flexible records, often JSON, grouped in collections | Data whose shape varies or changes often |
| Key value (NoSQL) | Each value found by a single key | Caches, settings, shopping baskets |
| Graph | Items and the links between them | Social networks, recommendations, route finding |
| Time series | Readings stamped with times | Sensors, stock prices, server monitoring |
| Vector | Lists of numbers that capture meaning | AI search: finding similar text or images |
"NoSQL" just means "not only SQL": databases that don't use the classic table model. Many apps use more than one type, for example a relational database for orders and a key value store as a fast cache. Try one: this question describes some data and asks whether SQL or NoSQL suits it better.
Decide whether each scenario suits SQL or NoSQL.
Press Mark to have your answer marked in the Databases course.
Keeping data safe: transactions
Say Sam sends Priya £50. The database must take £50 from Sam's balance and add £50 to Priya's. If the power failed between the two steps, money would vanish. Databases prevent this with transactions: a group of changes that either all happen or none do. PostgreSQL's documentation describes a transaction as bundling multiple steps into a single all or nothing operation. That guarantee is a big reason banks, shops and booking systems trust databases with their data.
Database examples in everyday life
- Online shopping: products, stock levels, customers, baskets and orders.
- Banking: accounts, balances and every transaction.
- Social media: profiles, posts, likes and who follows whom.
- Schools: pupils, timetables, attendance and grades.
- Your phone: contacts, messages and app data, often in SQLite files.
- Healthcare: patient records, appointments and prescriptions.
Common mistakes
- Calling the software the database. MySQL is a DBMS; the database is the data it manages. People often say both, but exams expect the difference.
- Mixing up records and fields. A record is a row (one item); a field is a column (one property).
- Choosing a primary key that can repeat, such as a name or a date of birth.
- Storing the same fact in many places. It causes redundancy and inconsistency.
- Thinking NoSQL means no structure. It means a different structure, not none.
- Treating a spreadsheet as a database for a big, shared system. It works until two people edit at once.
Common questions
What is a database in simple terms?
What is database software?
What are the main types of databases?
Is Excel a database?
What is SQL?
What is a primary key?
Revision cards
Read the front, say your answer, then flip to check.
Where to go next
- Learn it
Databases
SQL, NoSQL and everything in between for storing and querying data
Start the course - Test it
AP Computer Science Principles
A new exam-style paper every day, with instant marking and a mark scheme
Start today's paper - Test it
AP Computer Science A
A new exam-style paper every day, with instant marking and a mark scheme
Start today's paper