What Is a Database

A database is an organized collection of data stored so that programs can save it reliably, find it quickly, and change it safely — and it exists because a program's variables vanish the instant the program stops, while a database keeps information such as accounts, orders, and messages on disk so it survives restarts, crashes, and power loss. The variables from the programming-basics topic live in RAM, the fast but temporary memory from the first topic, which empties when the power goes off, so anything that must still exist tomorrow has to be written to storage. A plain file can hold data, but it gets painful quickly: finding one record means reading the whole file, two programs editing it at once can corrupt it, and nothing enforces any rules about what the data should look like. A database system is the software that sits between programs and the stored data to solve exactly those problems — it handles how data is organized, how it is searched, how many users can work at once, and how to avoid ever leaving a half-finished change behind. The most common kind is the relational database, which keeps data in tables: each table describes one kind of thing, such as customers or orders; each row is one record; and each column is one attribute with a defined type, the same idea as the data types in programming basics. A primary key is a column whose value is unique for every row, such as a customer ID, and a foreign key is a column that stores another table's key to link the two — so an order row holds the customer's ID instead of copying her name and address, which means each fact is stored exactly once and a change happens in a single place instead of drifting out of sync across many copies. SQL, short for Structured Query Language, is the standard language for talking to a relational database, and its key idea is that you describe what you want rather than how to find it: `SELECT name FROM customers WHERE city = 'Austin'` asks for every matching name, and the database decides the fastest way to get them. Nearly everything an application does with stored data comes down to four actions, often abbreviated CRUD — create new rows, read existing ones, update them, and delete them. Speed comes from an index, a separate sorted lookup structure kept for a column, much like the index at the back of a book: without one, finding a row means checking every row in a full scan, which is fine for a hundred rows and hopeless for a hundred million, while with one the database jumps almost straight to the match, using the same tree and hash-table ideas from the data structures topic — at the cost of extra space and slightly slower writes, because the index must be updated whenever the data changes. Safety comes from the transaction, a group of steps treated as one all-or-nothing unit: when a bank moves money, it must subtract from one account and add to another, and if a crash landed between the two steps the money would simply vanish, so the database guarantees that either both steps are saved or neither is. That guarantee is part of a famous set of promises called ACID — atomic (all or nothing), consistent (the rules always hold), isolated (users working at the same time do not see each other's half-finished changes, which avoids the same kind of race condition that threads can cause), and durable (once saved, it stays saved even through a crash). Not every database is relational: so-called NoSQL databases store data as flexible documents, simple key-value pairs, or other shapes, trading some of the strict structure for flexibility or scale, which makes them a different set of trade-offs for different needs rather than a replacement. In a typical application the database sits at the very back: your phone talks to a server through an API, the API-topic's agreed doorway, and the server program asks the database for what it needs, so the outside world never touches the data directly — which is also a safety feature, since access can be limited to the server alone. Because the cloud topic showed that computing can be rented, many teams rent a managed database too, letting the provider handle backups and scaling, though a database is only as safe as its most recent backup, the separate copy that protects against accidental deletion or hardware failure. Tying it together, a database is not a new kind of magic: it is a program that organizes data on storage with tables and keys, speeds up lookups with indexes, protects changes with transactions, and answers questions asked in a language like SQL — the long-term memory that lets every other program in this series remember anything at all.

A program's variables vanish
RAM empties when the program stops or power is lost
A database system keeps data on storage
organized, searchable, and shared safely by many users
Tables, rows, columns
one kind of thing per table, one record per row
Keys
a primary key identifies a row; a foreign key links tables
SQL
describe what you want; the database finds it
Index
a sorted lookup so a search skips the full scan
Transactions: all or nothing
a crash can never leave a change half done
The long-term memory behind every app
reached through an API, often rented in the cloud
Tables, Rows, Columns, and Keys each fact is stored once; other tables point to it by key customers id PK name city 7 Maya Austin 8 Leo Denver orders id PK customer_id FK item 101 7 Keyboard 102 7 Monitor 103 8 Mouse each order points to its customer by key Row one record about one thing such as one customer Column one attribute with a type such as a name or a city Key PK identifies a row; FK links to a row in another table change Maya's city once, and every order sees the update
An Index Skips the Full Scan same question, very different amount of work Without an index: full scan 1 2 3 4 5 6 ... check every row, one after another, until the match turns up a million rows can mean up to a million checks the work grows with the size of the table With an index: sorted lookup start here narrow down skipped skipped the match a handful of steps, even for millions of rows the trade-off: an index takes extra space and must be updated every time the data changes, so writes get slightly slower
A Transaction Is All or Nothing moving $100 from Account A to Account B takes two steps Step 1: subtract $100 from Account A Step 2: add $100 to Account B Both steps succeed: commit Account A: $500 → $400 Account B: $200 → $300 both changes are saved together the total money in the system is unchanged Crash after step 1: roll back step 1 is undone automatically Account A: back to $500 Account B: still $200 nothing is saved, so nothing is lost the transfer can simply be retried without a transaction, a crash between the steps would make $100 vanish

Take what is a database further

Ask the copilot about this term, or have our engineers assess it against your process.