← All articles
technologywhat is a databasedatabase basicsrelational databaseAugust 14, 20269 min read

What Is a Database? How Organised Data Can Be Stored and Queried

By the BrainSnail editorial team. How these articles are written and checked, and how to tell us when one is wrong.

A database is an organised collection of data designed so information can be stored, found, updated, and managed efficiently. Databases sit behind many apps and websites, from school systems and shops to games, libraries, and banking software.

What a database stores

Imagine a school needs to track students, classes, teachers, and grades. Saving everything in one long text file would make searching and updating awkward. A database can store the information in a structured form so software can ask specific questions, such as which students are enrolled in a class or which teacher is assigned to a room.

In a relational database, data is commonly organised into tables. A table contains rows, often called records, and columns that describe fields such as student ID, name, or date of birth. This table model is one common answer to what a database is, although other database designs organise information differently for different kinds of tasks.

Different database systems are chosen for different jobs. A relational database is strong when structured records and clear relationships matter, while document, key-value, graph, and other database models can fit less uniform or highly connected data. The best choice depends on how the application needs to read, write, scale, and connect information.

Why keys and relationships matter

A primary key uniquely identifies a record in a table. A student ID is usually safer than a name because two students may share the same name. Another table can store class enrolments and refer to the student ID, creating a relationship without copying every student detail again. This helps reduce duplication and keeps updates more consistent.

A database becomes especially useful when several types of data need to connect. A shop might have separate tables for customers, products, orders, and order items. Relationships let software connect a particular order with the correct customer and products. Good database design tries to make those connections clear while avoiding unnecessary repeated data.

Databases also need a system that manages how users and programs interact with the stored data. A database management system, or DBMS, handles tasks such as executing queries, enforcing rules, controlling concurrent access, and writing changes safely to storage. This layer matters when many users act at once. Without coordination, two updates could overwrite each other or a partial failure could leave records inconsistent. The DBMS helps turn stored information into a reliable shared service rather than just a pile of files.

Queries, updates, and data quality

A database becomes useful because software can work with the stored information:

  • •Queries retrieve records that match chosen conditions.
  • •Indexes can make common searches faster.
  • •Constraints can prevent some invalid or duplicate data.
  • •Transactions help keep related changes consistent.
  • •Permissions and backups help protect important information.

Many relational databases use SQL, a language for selecting, inserting, updating, and deleting data. Other systems use different query methods. Whatever the technology, a database also includes rules for data quality and access. Validation can reduce invalid entries, permissions can limit who may change sensitive records, and backups help recover from failures.

Worked example: asking a question across two tables

Picture two tables in a school database. The Students table has columns for student_id and name. The Enrolments table has columns for student_id and class_code, with one row for each student in each class. The names are stored only once, in Students, while Enrolments just records the links. Suppose a teacher asks which students take the class MATH7. The answer is split across both tables: the class codes are in one place and the names are in the other. A relational database is designed for exactly this kind of question.

In SQL the request could read: SELECT Students.name FROM Students JOIN Enrolments ON Students.student_id = Enrolments.student_id WHERE Enrolments.class_code = 'MATH7'. The JOIN matches rows where the student IDs agree, the WHERE line keeps only the MATH7 enrolments, and SELECT returns just the names. Notice that the query describes the result you want, not the steps to find it. The database decides how to carry it out, perhaps using an index on class_code. If a student changes their name, it is updated in one row and every future query shows the new name automatically.

How an index makes searching fast

Without an index, a database answering a question such as which customer has the email address you just typed must check every row in turn, which is called a full table scan. With a million customers, that could mean a million comparisons. An index works like the index at the back of a book: a separate, sorted structure listing the values in one column alongside the location of each matching row. Because it is sorted, the database can repeatedly halve the range it is searching, and halving a million possibilities takes only about twenty steps.

Real systems usually store indexes as B-trees, wide and shallow trees in which each node can point to hundreds of children, so even very large tables can be searched by visiting just a handful of nodes. A common misconception is that adding more indexes always makes a database faster. Each index takes up storage, and every time a row is inserted, updated or deleted, each relevant index must be updated too, which slows down writing. Designers therefore index the columns that are searched or joined most often, such as IDs and email addresses, and leave the rest alone.

SQL injection: when data becomes instructions

Databases are often attacked through the way programs build their queries. Suppose a login page takes whatever a user types and pastes it straight into an SQL statement, so that the query reads SELECT * FROM Users WHERE name = followed by the typed text inside quotation marks. If someone types a quotation mark followed by extra SQL, such as ' OR '1'='1, the database no longer sees a name. It sees a condition that is always true, and may return every user in the table. This attack is called SQL injection, and it has been behind many real data breaches.

The cause is mixing data with instructions, so the fix is to keep them apart. Instead of gluing text together, programmers use parameterised queries, also called prepared statements. The query is written with a placeholder, such as WHERE name = ?, and the user's input is sent separately as a value. The database then treats it purely as data, however many quotation marks it contains. Good practice adds further layers: giving the application's database account only the permissions it actually needs, and storing passwords as salted hashes rather than plain text, so that even a successful attack reveals less.

The takeaway

A database is a structured system for storing and managing data so software can retrieve, connect, and update information reliably. Tables, records, keys, and queries are core ideas in relational databases, but the larger goal is simple: organise data so it remains useful as the amount and complexity of information grow.

Practise this

Questions from Data and Information

Reading about something is not the same as being able to recall it. These are real questions from the Data and Information unit in our Technology track, answers and explanations included. The unit has 119 in total across 23 steps.

  • Fill the blankLevel 2

    1. A database often keeps information in rows and ____.

    • columnscorrect
    • clouds
    • wires
    • songs

    Data is organized into rows and columns, a bit like a neat table.

  • Choose all that applyLevel 3

    2. Which of these are real ways computers encode information? Pick all that apply.

    • Letters stored as numberscorrect
    • Images stored as pixelscorrect
    • Sound stored as numberscorrect
    • Ideas stored as magic

    Computers store letters as numbers, images as pixels and sounds as numbers too.

  • Guess the numberLevel 3

    3. What is the binary number 111 equal to in decimal?

    Answer: 7

    Binary 111 is 4 plus 2 plus 1, which equals 7.