What a Database Is — How It Differs from a File, Tables, and SQL

This article is part of the IT Foundations course, which builds up from scratch the practical IT knowledge you need at a minimum for programming and vibe coding.
A database takes on three jobs: searching, handling writes that arrive at the same time, and fixing the shape of records. The diagrams cover tables made of rows and columns, and the SQL that instructs reads and writes.

This article covers the DB tier, that is, the database.

A database is software that stores data in a form that can be searched and updated.

What makes it different from a file is not where the records sit, but that it also takes on the searching and the ordering of writes.

The words used in beginner instructions, and where database, table, and SQL fit
===Save it to thedatabaseCreate atableWrite SQLDatabaseTableSQLSoftware inthe DB tierA table insidethe databaseInstructions sentfrom the App tier
The top row is the wording that appears in instructions, the middle row is the three terms this article covers, and the bottom row is where each sits in the three-tier model. The two joined by a double line differ only in wording; they are the same thing.

How a database differs from a file — searching, simultaneous writes, and a fixed shape

A database is not just a container that stores records.

It takes on three jobs: finding the rows that match a condition, processing simultaneous writes one after another, and keeping the shape of records consistent.

Even when they arrive at the same time, writes are processed one at a time, in order.

If you write straight to a file, your own program has to decide that order.

Who holds each role, with a file and with a database
===Find records thatmatch a conditionOrder simultaneouswritesKeep the shape ofrecords consistentYour program readsit all and picksYou decide theorder yourselfThe writer hasto be carefulDatabase returnsonly matching rowsDatabase processesthem in orderIt refuses rowsthat do not fitGets slower asrows pile upWriting at onceloses one of themMismatched recordsget mixed in
The left column is the role, and the two middle columns are the file case and the database case. The right-hand column is what tends to happen when you hold the role yourself.

Commonly used databases are PostgreSQL, MySQL, and SQLite.

Records that only one person edits, such as settings, are fine left as a file.

Records that several people read and write at the same time and that you search by condition are what goes in a database.

A database takes on three jobs

With both a file and a database the records stay on storage; what differs is who does the searching, who sets the order when writes arrive at the same time, and who keeps the shape of records consistent.

With a file your own program does all of it, and with a database you only state which records you want, and rows whose shape does not fit are refused for you.

A table stores records as a grid of rows and columns

The unit that stores records inside a database is a table — a grid of rows and columns that gathers records of the same kind.

Booking IDMember IDDateGuests
1122026-10-032
272026-10-034
3122026-10-103

Each heading is a column, a single item of a record, and each horizontal line below it is a row, one complete record.

The column that pins a row down to exactly one is the primary key, a column in which no two rows can hold the same value.

The columns are decided in advance, and one row is added each time a record is added.

Inside the booking app's database
The booking app's database
Bookings table
  • Columns: booking ID, member ID, date, guests
  • 1 row = 1 booking
  • A row is added for each booking
Members table
  • Columns: member ID, name, email address
  • 1 row = 1 member
  • A row is added for each sign-up
The outer frame is one database. The two inside are tables, and each bullet list gives the column names and what one row represents.

The bookings table does not hold the member's name, only the member ID.

The name exists in exactly one place, the members table, so when it changes there is one row to fix.

One sign-up is split across two tables
Alice's sign-up10/03 · 2 peopleName and email tothe members tableDate and guests tothe bookings tableMembers tablemember ID 12 · AliceBookings tableID 1 · member ID 12Same member ID
The single entry on the left splits up and down, each becoming a row in a different table. The two on the right hold the same value, member ID 12, so you can follow a booking row to the name.

A database that holds data as a grid of rows and columns is a relational database, also written RDB, and tables can be linked to one another through a shared column.

What you decide before creating a table is the schema — the table name, the column names, and the kind of value each column holds — where the kind of value means a distinction such as number, text, or date, also written as the type.

A table fixes its columns first and grows by rows

A table is a grid made of vertical columns and horizontal rows.

The column names are decided in advance, one row is added for each new record, and when you also put the primary key value that identifies a record into another table, the two are linked.

SQL is how the application server tier writes the read and write instructions it sends to the database

The way you write instructions to read from and write to a table is SQL (Structured Query Language), a language for instructing reads, inserts, updates, and deletes of rows, and one instruction is called a query.

Beginner guides show it in the following form.

SELECT date, guests
FROM reservations
WHERE member_id = 12;

After SELECT come the columns to take out, after FROM comes the table, and after WHERE comes the condition.

These three lines instruct the database to take the date and guests from the rows in the bookings table whose member ID is 12.

The first word tells you which it is: a read, an insert, an update, or a delete.

The first word determines what the database does
SELECT ...WHERE member_id= 12INSERT INTOreservations ...UPDATE ...SET guests = 4DELETE FROMreservations ...Pick the rows withmember ID 12Add one row tothe bookings tableChange guests onthe matching rowsDelete matching rowsDate and guestscome back, 2 rowsOne row is added2 becomes 4One row is removed
The left is the start of the query you sent, the middle is what the database does, and the right is what comes back and what is left. The bottom three change the number of rows; only the top one is a read.

Finding rows is the database's work, and the application server tier only states which rows it wants.

With updates and deletes, what changes is not the rows returned but the rows left in the table.

The component that lets you work with tables in the syntax of your language instead of writing SQL is an ORM (Object-Relational Mapping), which handles table rows in the language's own syntax, converts that to SQL, and sends it.

Whether you write SQL directly or use an ORM, what arrives is the same
Write SQL directlySent as it isWrite in ORM syntaxThe ORM convertsit to SQLOne SQL queryreaching the database
The lines you write differ between the top and the bottom, but they merge into one at the right. What the database receives is an SQL query either way.

Even when you use an ORM, what arrives is an SQL query.

Writing and running SQL yourself is covered in the SELECT article in the SQL beginner course.

SQL is how you state the rows you want

SQL is how you write a request to read from or write to a database.

The first word settles whether you are reading, adding, changing, or deleting; you state which rows are affected as a condition, and the database does the searching.

QUIZ

Knowledge Check

Answer each question one by one.

Q1Which difference given in this article is a reason to keep booking records in a database rather than a file?

Q2What does the query SELECT date, guests FROM reservations WHERE member_id = 12; instruct?

Q3Why does the bookings table hold the member ID rather than the member's name?