> ## Documentation Index
> Fetch the complete documentation index at: https://miliracle.online/llms.txt
> Use this file to discover all available pages before exploring further.

# What Is a Database?

> From punch-card trees to databases that tune themselves: a visual guide to where your data actually lives.

export const QUIZ = [{
  q: "What does a DBMS do?",
  a: ["Stores only spreadsheets", "Sits between users and data, handling queries, access and backups", "Designs websites"],
  c: 1,
  why: "The DBMS is the interface between the database and its users or programs."
}, {
  q: "Which model organizes data in tables of rows and columns?",
  a: ["Hierarchical", "Relational", "Graph"],
  c: 1,
  why: "Relational databases became dominant in the 1980s and still store data in linked tables."
}, {
  q: "Why pick a database over a spreadsheet?",
  a: ["Many users need fast, secure access to lots of data at once", "It has prettier charts", "It only works offline"],
  c: 0,
  why: "Spreadsheets were designed for one user; databases handle many concurrent users and large volumes."
}, {
  q: "Which type is built for analysis across many systems?",
  a: ["OLTP", "Data warehouse", "Hierarchical"],
  c: 1,
  why: "A data warehouse is a central repository designed for fast query and analysis. OLTP handles transactions."
}];

export const CHALLENGES = [["Volume", 92, "Sensors, apps and machines keep adding data faster than teams can organize it."], ["Security", 86, "Data must resist breaches yet stay easy for the right people to reach."], ["Real-time demand", 74, "Decisions need fresh data now, not after tonight's batch job."], ["Maintenance", 80, "Monitoring, patching and upgrades need skilled, costly staff."], ["Scalability", 68, "Future capacity is hard to predict, especially on-premises."], ["Residency", 55, "Some data must stay in a country or on-site for legal or latency reasons."]];

export const TYPES = [{
  n: "Relational",
  i: `<rect x="4" y="4" width="36" height="24" rx="3" class="s-acc"/><path d="M4 12h36M4 20h36M16 4v24" class="s-acc"/>`,
  what: "Tables of rows and columns, linked by keys, queried with SQL.",
  use: "Orders, accounts, inventory: structured data that must stay consistent.",
  eg: "MySQL, PostgreSQL, Oracle Database"
}, {
  n: "Document / JSON",
  i: `<path d="M10 3h16l8 8v18H10z M26 3v8h8" class="s-acc"/><path d="M15 17h12M15 22h9" class="s-acc"/>`,
  what: "Each record is a self-contained JSON document; fields can vary between records.",
  use: "Product catalogs, user profiles, content that changes shape often.",
  eg: "MongoDB, Couchbase"
}, {
  n: "Graph",
  i: `<circle cx="8" cy="8" r="4" class="s-acc"/><circle cx="36" cy="10" r="4" class="s-acc"/><circle cx="22" cy="26" r="4" class="s-acc"/><path d="M12 9l20 1M10 12l9 11M33 13l-8 10" class="s-acc"/>`,
  what: "Stores entities as nodes and the relationships between them as edges.",
  use: "Social networks, recommendations, fraud rings.",
  eg: "Neo4j, Amazon Neptune"
}, {
  n: "Distributed",
  i: `<rect x="2" y="4" width="12" height="10" rx="2" class="s-acc"/><rect x="30" y="4" width="12" height="10" rx="2" class="s-acc"/><rect x="16" y="20" width="12" height="10" rx="2" class="s-acc"/><path d="M14 9h16M10 14l8 6M34 14l-8 6" class="s-acc"/>`,
  what: "One database spread over several machines, in one building or across networks.",
  use: "Services that must stay up and fast for users worldwide.",
  eg: "CockroachDB, Cassandra"
}, {
  n: "Data warehouse",
  i: `<path d="M4 14L22 4l18 10v14H4z" class="s-acc"/><path d="M12 28v-8h6v8M24 28v-12h6v12" class="s-acc"/>`,
  what: "A central store that gathers data from many systems, built for fast analysis.",
  use: "Reports and dashboards across the whole business.",
  eg: "Snowflake, BigQuery, Redshift"
}, {
  n: "OLTP",
  i: `<path d="M24 3L10 18h10l-4 11 16-16H22z" class="s-acc"/>`,
  what: "Online transaction processing: many small reads and writes from many users, each finished in milliseconds.",
  use: "Checkouts, bank transfers, bookings.",
  eg: "Usually a relational DBMS tuned for transactions"
}, {
  n: "Cloud",
  i: `<path d="M12 26a7 7 0 0 1 0-14 10 10 0 0 1 19 2 6 6 0 0 1 1 12z" class="s-acc"/>`,
  what: "Runs on a public, private or hybrid cloud. With database as a service, the provider handles admin and maintenance.",
  use: "Teams that want capacity on demand without running servers.",
  eg: "Amazon RDS, Azure SQL, Oracle Autonomous Database"
}, {
  n: "Self-driving",
  i: `<circle cx="22" cy="16" r="7" class="s-acc"/><path d="M22 3v5M22 24v5M9 16h5M30 16h5M13 7l3 3M31 25l-3-3M13 25l3-3M31 7l-3 3" class="s-acc"/>`,
  what: "A cloud database that uses machine learning to tune, secure, back up and update itself.",
  use: "Cutting routine administrator work so people can focus on the data.",
  eg: "Oracle Autonomous Database (first announced 2017)"
}];

export const RaceLane = ({title, users, time, width, note}) => <div className="hdw-stack">
    <div className="hdw-lane-head"><h3>{title}</h3><span className="hdw-clock">{time.toFixed(1)}s</span></div>
    <div className="hdw-users">{users.map((u, k) => <div key={k} className={`hdw-user ${u}`}>U{k + 1}</div>)}</div>
    <div className="hdw-bar"><i style={{
  width: `${width}%`
}} /></div>
    <p className="hdw-muted" style={{
  fontSize: "0.88rem"
}}>{note}</p>
  </div>;

export const ERAS = [{
  yr: "1960s",
  name: "Hierarchical",
  tag: "Tree · one-to-many",
  text: "Records hang off a single parent, like folders in folders. Fast for fixed paths, but a child can only have one parent, so many real relationships don't fit.",
  svg: () => `<path d="M150 46 L70 120 M150 46 L150 120 M150 46 L230 120 M70 146 L40 214 M70 146 L100 214 M230 146 L230 214" class="s-ink"/>${box(127, 20)}${box(47, 120)}${box(127, 120)}${box(207, 120)}${box(17, 214)}${box(77, 214)}${box(207, 214)}`
}, {
  yr: "1960s–70s",
  name: "Network",
  tag: "Graph of records · many-to-many",
  text: "Records can link to several others, so it handles more relationships than a tree. Programs still had to navigate the links by hand, which made changes painful.",
  svg: () => `<path d="M70 50 L230 50 M70 50 L150 140 M230 50 L150 140 M70 50 L60 220 M150 140 L60 220 M150 140 L240 220 M230 50 L240 220 M60 220 L240 220" class="s-ink"/>${box(47, 37)}${box(207, 37)}${box(127, 127)}${box(37, 207)}${box(217, 207)}`
}, {
  yr: "1980s",
  name: "Relational",
  tag: "Tables + SQL",
  text: "Data lives in tables of rows and columns, and tables relate through shared keys. You describe what you want in SQL and the DBMS works out how to get it. Still the most common model today.",
  svg: () => `${box(20, 40, 110, 150)}<path d="M20 70 H130 M20 100 H130 M20 130 H130 M20 160 H130 M60 40 V190" class="s-ink"/>${box(170, 70, 110, 120)}<path d="M170 100 H280 M170 130 H280 M170 160 H280 M210 70 V190" class="s-ink"/><path d="M130 115 C150 115,150 145,170 145" class="s-hit"/>`
}, {
  yr: "1990s",
  name: "Object-oriented",
  tag: "Objects, as in code",
  text: "Data is stored as objects with properties, matching how object-oriented programs model the world. Useful for complex structures such as engineering designs.",
  svg: () => `${box(90, 30, 120, 70)}<path d="M90 56 H210" class="s-ink"/><text x="150" y="50" text-anchor="middle" font-size="14" font-weight="700">Customer</text><text x="104" y="78" font-size="12" class="t-muted hdw-mono">name, orders[]</text><path d="M150 100 V140 M150 140 L80 170 M150 140 L220 170" class="s-ink"/>${box(30, 170, 100, 50)}${box(170, 170, 100, 50)}<text x="80" y="200" text-anchor="middle" font-size="13">Order</text><text x="220" y="200" text-anchor="middle" font-size="13">Address</text>`
}, {
  yr: "2000s",
  name: "NoSQL",
  tag: "Flexible schema · web scale",
  text: "The web brought huge volumes of unstructured and semi-structured data. NoSQL stores (documents, key-value, graph) drop the fixed table layout to gain speed and flexibility.",
  svg: () => `${box(30, 30, 110, 90)}${box(160, 60, 110, 130)}${box(50, 140, 110, 70)}<text font-size="12" class="hdw-mono"><tspan x="40" y="54">{ "name":</tspan><tspan x="48" y="72">"Linh",</tspan><tspan x="40" y="90">  "tags":[…] }</tspan><tspan x="170" y="84">{ "sku": 88,</tspan><tspan x="178" y="102">"sizes":</tspan><tspan x="178" y="120">["S","M"],</tspan><tspan x="178" y="138">"stock": 4 }</tspan><tspan x="60" y="168">{ "id": 9 }</tspan></text>`
}, {
  yr: "2010s →",
  name: "Cloud & autonomous",
  tag: "Managed · self-driving",
  text: "Databases now run on cloud platforms, often as a service where the provider handles maintenance. Self-driving databases (first announced in 2017) use machine learning to automate tuning, patches and backups.",
  svg: () => `<path d="M80 130 a40 40 0 0 1 30 -66 a55 55 0 0 1 100 14 a36 36 0 0 1 10 72 H90 a28 28 0 0 1 -10 -20z" class="s-ink"/><g class="s-acc" style="stroke-width:3"><circle cx="150" cy="120" r="22"/><path d="M150 92 v-8 M150 156 v-8 M122 120 h-8 M186 120 h-8"/></g><path d="M100 200 h100" class="s-hit"/><text x="150" y="226" text-anchor="middle" font-size="12" class="t-muted hdw-mono">tune · patch · back up</text>`
}];

export const box = (x, y, w = 46, h = 26) => `<rect x="${x}" y="${y}" width="${w}" height="${h}" rx="5" class="s-ink f-card"/>`;

export const SqlText = ({text}) => text.split(new RegExp(SQL_KW.source, "g")).map((part, i) => i % 2 ? <span key={i} className="hdw-kw">{part}</span> : part);

export const SQL_KW = /\b(SELECT|FROM|WHERE|UPDATE|SET|INSERT|INTO|VALUES)\b/;

export const QUERIES = [{
  label: "Find by city",
  sql: "SELECT * FROM customers\nWHERE city = 'Hanoi';",
  kind: "select",
  test: r => r[2] === "Hanoi",
  cols: [0, 1, 2, 3]
}, {
  label: "Filter by number",
  sql: "SELECT name, orders FROM customers\nWHERE orders > 8;",
  kind: "select",
  test: r => r[3] > 8,
  cols: [1, 3]
}, {
  label: "Update a row",
  sql: "UPDATE customers SET orders = orders + 1\nWHERE id = 3;",
  kind: "update",
  test: r => r[0] === 3
}, {
  label: "Insert a row",
  sql: "INSERT INTO customers (id, name, city, orders)\nVALUES (7, 'Priya', 'Pune', 1);",
  kind: "insert"
}];

export const SEED = [[1, "Linh", "Hanoi", 12], [2, "Marco", "Milan", 4], [3, "Aiko", "Osaka", 9], [4, "Tuan", "Hanoi", 3], [5, "Sara", "Lisbon", 15], [6, "Bao", "Da Nang", 7]];

export const useOnceVisible = (ref, onEnter) => {
  const cb = useRef(onEnter);
  cb.current = onEnter;
  useEffect(() => {
    const el = ref.current;
    if (!el) return;
    if (typeof IntersectionObserver === "undefined") {
      cb.current();
      return;
    }
    const io = new IntersectionObserver(entries => {
      if (entries.some(e => e.isIntersecting)) {
        io.disconnect();
        cb.current();
      }
    }, {
      threshold: 0.35
    });
    io.observe(el);
    return () => io.disconnect();
  }, [ref]);
};

export const useReducedMotion = () => {
  const [reduce, setReduce] = useState(false);
  useEffect(() => {
    const mq = window.matchMedia("(prefers-reduced-motion: reduce)");
    setReduce(mq.matches);
    const on = e => setReduce(e.matches);
    mq.addEventListener("change", on);
    return () => mq.removeEventListener("change", on);
  }, []);
  return reduce;
};

> This is the Markdown version of an interactive page. Every animated figure on the web page is replaced here by a table or code block with the same facts. Source: adapted from Oracle's overview ["What Is a Database?"](https://www.oracle.com/database/what-is-database/).

Every time you check a bank balance, book a seat or scroll a feed, a database answers a question for you in a few milliseconds. It is one of the most used and least seen pieces of software in the world.

A **database** is an organized collection of structured information, stored electronically and controlled by a **database management system**, or DBMS. The data, the DBMS and the applications that use them together form a *database system*, though most people simply call the whole thing "the database".

In the most common databases, data is laid out in **tables**. Each row is one record, such as a customer. Each column is one attribute of that record, such as a city or an order count. That simple grid is what makes data quick to search, update and organize.

<Tip>
  **In short**

  * A database stores structured data; a DBMS manages every read and write.
  * Most databases use tables and the SQL language.
  * Data models moved from trees (1960s) to tables (1980s) to flexible NoSQL and cloud services.
  * The right type depends on how the data will be used.
</Tip>

## Asking questions with SQL

You talk to a relational database in **SQL**, the Structured Query Language. IBM developed it in the 1970s, with Oracle as a major early contributor, and it became an ANSI standard. Nearly every relational database still speaks it, with extensions from vendors like IBM, Oracle and Microsoft.

SQL is declarative: you describe *what* you want, and the database works out *how* to find it. Without an index, the simplest strategy is to check every row and keep the ones that match. Figure 1 shows exactly that.

Example table `customers`:

| id | name | city | orders |
| - | - | - | - |
| 1 | Linh | Hanoi | 12 |
| 2 | Marco | Milan | 4 |
| 3 | Aiko | Osaka | 9 |
| 4 | Tuan | Hanoi | 3 |
| 5 | Sara | Lisbon | 15 |
| 6 | Bao | Da Nang | 7 |

```sql theme={null}
-- Read: every customer in Hanoi (rows 1 and 4)
SELECT * FROM customers WHERE city = 'Hanoi';

-- Read selected columns: customers with more than 8 orders (Linh, Aiko, Sara)
SELECT name, orders FROM customers WHERE orders > 8;

-- Change: give customer 3 one more order (9 -> 10)
UPDATE customers SET orders = orders + 1 WHERE id = 3;

-- Add: a new record
INSERT INTO customers (id, name, city, orders) VALUES (7, 'Priya', 'Pune', 1);
```

Four verbs cover most daily work: `SELECT` reads, `UPDATE` changes, `INSERT` adds and `DELETE` removes. The `WHERE` clause narrows any of them to the rows you mean.

## The DBMS in the middle

Apps never open the stored files themselves. Every request goes through the DBMS, which acts as the interface between the data and everyone who needs it. Familiar examples include MySQL, Microsoft SQL Server, Oracle Database, Microsoft Access, FileMaker Pro and dBASE.

What a DBMS does:

* **Retrieve and update** data for many users at the same time.
* **Control access**: who may read or change which data.
* **Look after it**: performance monitoring, tuning, backup and recovery.

One DBMS deserves a mention for its reach. **MySQL** is an open source relational system built for web applications. It runs on almost any platform and handles millions of queries, which is why it powers services like Airbnb, Uber, LinkedIn and YouTube.

## Sixty years of data models

The first databases of the early 1960s were *navigational*: programs had to walk from record to record along fixed paths. They worked, but they were rigid. Each generation since has fixed a limit of the one before it.

| Era | Model | Key idea | Limitation it addressed |
| - | - | - | - |
| 1960s | Hierarchical | Tree; each record has one parent (one-to-many) | First way to store and navigate data |
| 1960s–70s | Network | Records link to many others (many-to-many) | Trees could not express many relationships |
| 1980s | Relational | Tables related by keys, queried with SQL | Navigational models were rigid and hard to change |
| 1990s | Object-oriented | Data stored as objects, like in OOP | Complex structures that map awkwardly to tables |
| 2000s | NoSQL | Flexible schemas for unstructured and semi-structured data | Speed and scale demands of the web |
| 2010s onward | Cloud and self-driving | Managed services; machine learning automates tuning, patching, backups | Cost and effort of running databases by hand |

> The relational model won because it let people ask new questions without rewriting the program.

## Why not a spreadsheet?

Spreadsheets and databases both store information, but they were built for different jobs. They differ in how data is stored and manipulated, who can access it, and how much it can hold.

A spreadsheet was designed for one person working on one file. A database is designed for large volumes of data and many people querying and changing it at the same time, securely and with complex logic. Figure 4 runs the same six requests against each.

| | Spreadsheet | Database |
| - | - | - |
| Designed for | One user, or a few | Many users at the same time |
| Data volume | Small to moderate | Very large |
| Manipulation | Simple formulas and edits | Complex queries and logic |
| Access | Share the file | Secure, controlled, concurrent access |

## Types of databases

There are several dozen kinds of database, and the best one depends on how the data will be used. Here are the ones you will meet most often.

| Type | What it is | Good for | Examples |
| - | - | - | - |
| Relational | Tables of rows and columns linked by keys; SQL | Orders, accounts, inventory | MySQL, PostgreSQL, Oracle Database |
| Document / JSON | Self-contained JSON documents; fields can vary | Catalogs, profiles, content | MongoDB, Couchbase |
| Graph | Entities as nodes, relationships as edges | Social networks, recommendations, fraud detection | Neo4j, Amazon Neptune |
| Distributed | One database spread across machines or sites | Availability and scale across regions | CockroachDB, Cassandra |
| Data warehouse | Central store built for fast analysis | Business reporting and analytics | Snowflake, BigQuery, Redshift |
| OLTP | Many short transactions from many users | Checkouts, payments, bookings | Usually a relational DBMS tuned for transactions |
| Cloud | Public, private or hybrid cloud; traditional or DBaaS | Capacity on demand without running servers | Amazon RDS, Azure SQL |
| Self-driving | Cloud database that uses machine learning to run itself | Reducing routine administration | Oracle Autonomous Database |

OLTP systems handle transactions; analysis workloads usually go to a data warehouse (OLAP).

Two more labels describe how a database is built or delivered rather than its shape. An **open source** database publishes its code and can be SQL or NoSQL. A **multimodel** database combines several models, such as tables, documents and graphs, in one back end.

## What makes it hard

Large databases are expected to answer complex queries almost instantly. Keeping that promise puts constant pressure on the people who run them.

1. **Volume**: sensors, apps and machines keep adding data faster than teams can organize it.
2. **Security**: data must resist breaches yet stay easy for the right people to reach.
3. **Real-time demand**: decisions need fresh data now, not after tonight's batch job.
4. **Maintenance**: monitoring, patching and upgrades need skilled, costly staff.
5. **Scalability**: future capacity is hard to predict, especially on-premises.
6. **Residency**: some data must stay in a country or on-site for legal or latency reasons.

## Self-driving databases

Today many databases run in the **cloud**, either as a traditional install on cloud machines or as **database as a service**, where the provider handles administration.

The newest step is the **self-driving** or autonomous database. It uses machine learning to handle tuning, security, backups and updates that administrators used to do by hand. The first one was announced in late 2017. The goal is to free people from routine upkeep so they can spend time on what the data means.

## Check yourself

Questions this document answers:

* What is the difference between a database and a DBMS? The DBMS is the software that sits between the data and its users.
* Which model organizes data in tables? Relational.
* Why pick a database over a spreadsheet? Many users need fast, secure access to lots of data at once.
* Which type is built for analysis across many systems? A data warehouse.
* When was the first self-driving database announced? Late 2017.

## Glossary

| Term | Meaning |
| - | - |
| Database | An organized collection of structured data stored electronically. |
| DBMS | Software that manages a database and handles every request to it. |
| Table | A grid of rows (records) and columns (attributes). |
| SQL | Structured Query Language, used to query and define relational data. |
| Schema | The defined structure that stored data must follow. |
| NoSQL | Non-relational databases with flexible or no fixed schema. |
| DBaaS | Database as a service; the provider runs the maintenance. |
| OLTP | Online transaction processing: many small, fast reads and writes. |
| Data warehouse | A central store built for analysis across many systems. |

## For AI agents

You are reading the Markdown export of `/writing/database/what-is-a-database`. The web page has the same text plus interactive figures; nothing factual is missing here. The site index for agents is at `/llms.txt`.

***

Adapted from Oracle's overview ["What Is a Database?"](https://www.oracle.com/database/what-is-database/). Figures are simplified teaching models; timings in Figure 4 are illustrative.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.