Skip to content
Tutorials Center
My learning

Topics

Lesson 1 of 79 ยท Introduction to Databases

What Is a Database?

Learn what a database is, how data differs from information, what a DBMS does for you, and run your first queries against a small bookstore database in the browser.

Almost every application you use keeps something somewhere: a shop remembers what it sells, a bank remembers your balance, a game remembers your level. A database is an organized collection of related data that is stored so that it can be found, changed and protected over a long time. The key words are organized and related. A folder full of unrelated notes is storage; a database has structure that both people and programs can rely on.

This lesson lays the vocabulary for the whole tutorial. You will learn the difference between data and information, between a database and the software that manages it (the DBMS), and you will query a tiny real database right in your browser. Later lessons open the box and show how each part works.

Data and information

Data is a raw fact with no context: 1984, 9.99, Orwell. On their own they mean little. Information is data that has been given context and meaning so that it helps someone decide or act: "The book 1984 by Orwell was published in 1949 and costs 9.99."

A database stores data. A query turns it into information. When you ask "which books cost less than ten dollars?", the answer is information built from many stored facts.

From raw facts to answers

Data Raw values with no context, like 1949 or Orwell.
Database Organized, related data stored for the long term.
Query A question asked in a language like SQL.
Information The answer, with meaning attached.

The database holds the data; queries produce information.

1 / 2

Database versus DBMS

People say "database" for two different things, and it helps to separate them.

  • The database is the data itself, plus the description of its structure, stored on disk.
  • The database management system (DBMS) is the software that creates, reads, changes, protects and shares that database. SQLite, PostgreSQL, MySQL, SQL Server and Oracle are DBMSs. MongoDB and Redis are DBMSs too, just with different data models (see Data Models Compared).

A database system is the whole package: the data, the DBMS and the applications that talk to it. An application never opens the database file and edits bytes by hand. It asks the DBMS, and the DBMS decides how to do the work safely.

Anatomy of a relational database

Most databases you will meet are relational. They store data in tables. A table has named columns (the attributes) and a row for every item (a record). The design of the tables, columns and their rules is called the schema. The rows that exist right now are the instance. Schemas, Instances and Data Independence goes deeper on that split.

The browser examples in this tutorial use a small bookstore with four tables: authors, books, customers and orders. Run the next example to see the books table.

SQL Your first query ยท database: bookstore

Press Run (or Ctrl + Enter) to see the result here.

You wrote what you wanted: five books, with four columns, in a certain order. You did not say how to open a file, scan it or sort it. That is the first big gift of a DBMS: a declarative query language, where you describe the result and the system works out the method.

What a DBMS does for you

If you had to build a program that stores bookstore data yourself, you would soon be writing a lot of code that has nothing to do with books. A DBMS gives you these services out of the box:

  1. Data definition. You declare tables, column types and rules, and the DBMS stores that description in its catalog.
  2. Querying and updating. One language (SQL for relational systems) reads and changes data, from one row to millions.
  3. Integrity. Rules such as "a price cannot be negative" or "an order must point to a real customer" are enforced for every program that touches the data.
  4. Concurrency. Many users can read and write at the same time without trampling each other's work.
  5. Recovery. After a crash or power cut, the database comes back in a consistent state.
  6. Security. Different users get different permissions.
  7. Performance. Indexes and a query optimizer find rows quickly without you hand-coding loops.

Each of these has its own chapter later. For now, notice how much of this list you would never want to write yourself.

Data about different things goes into different tables, and the tables point at each other with identifiers. A book does not store the author's name and country; it stores an author_id. A join follows that pointer.

SQL Following a relationship ยท database: bookstore

Press Run (or Ctrl + Enter) to see the result here.

Each author is stored exactly once, however many books they wrote. Fix a typo in an author's name in one place and every book reflects it. File Systems vs a DBMS shows what goes wrong without this approach.

Asking questions with aggregates

A database is not only for fetching single rows. Summaries are cheap too.

SQL Summaries across many rows ยท database: bookstore

Press Run (or Ctrl + Enter) to see the result here.

Here count and avg collapse many rows into one row per genre. You will see the exact theory behind this in Queries Through the Lens of Theory.

Who uses a database?

Several kinds of people touch a database system, and the roles shape how DBMS features are designed:

  • End users use applications and never see SQL.
  • Application developers write programs that send queries to the DBMS.
  • Database designers decide the schema: tables, keys and rules. Most of this tutorial is for them.
  • Database administrators (DBAs) install, tune, back up and secure the system.

On a small project one person wears all four hats.

What runs live here. SQL examples in this tutorial run in your browser using SQLite compiled to WebAssembly, with a fresh in-memory database each time you press Run. Features that only exist on database servers (user accounts, replication, procedural languages) are shown as read-only code and clearly labeled.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which statement best describes the difference between data and information?

    Data becomes information when it is interpreted in context, for example by a query that answers a question.
  2. 2. What is a DBMS?

    The database is the data and its structure. The DBMS is the software that manages it. The person is the DBA.
  3. 3. Why does the books table store an author_id instead of the author's name?

    Storing the author once avoids repeated, possibly inconsistent copies. A join follows the identifier when you need the name.
  4. 4. What does it mean that SQL is declarative?

    In a declarative language you state what you want. The query optimizer picks the steps.

Summary

  • A database is an organized collection of related data; a DBMS is the software that manages it; the database system is both plus the applications.
  • Data are raw facts; information is data with meaning, produced by queries.
  • Relational databases store data in tables with columns (attributes) and rows, described by a schema.
  • A DBMS provides a query language, integrity rules, concurrency control, recovery, security and performance tools.
  • Related data is split across tables and recombined with joins.

Next, see why this is better than keeping your data in plain files: File Systems vs a DBMS.