// Learn

What is a database?

A database is an organised store of data that applications can read from and write to.

The short version

Every app that remembers anything uses a database. Your user account, your saved preferences, your order history. The app writes data to the database when you do something, and reads it back when it needs to show you something. Without a database, every page refresh would start from scratch.

There are different types of database, but two dominate: relational databases (like PostgreSQL, MySQL) and document databases (like MongoDB, Firestore). For most things you'll build with AI tools, you'll encounter relational databases.

How it works

A relational database organises data into tables with rows and columns, similar to a spreadsheet but with strict rules:

  • Tables hold one type of thing. A users table, an orders table, a products table.
  • Rows are individual records. One row per user, one row per order.
  • Columns define the fields. name, email, created_at.
  • Primary keys uniquely identify each row (usually an id column).
  • Foreign keys link tables together. An order row has a customer_id that points to a row in the customers table.

You interact with relational databases using SQL (Structured Query Language):

SELECT name, total FROM orders WHERE customer_id = 42;

That reads: "get the title and duration of all speeches by speaker 42."

Managed database services like Supabase, PlanetScale, and Neon handle the infrastructure for you. You get a database URL (which goes in an environment variable), a web dashboard for browsing your data, and an API for your app to connect through.

Airtable sits in a middle ground. It looks like a spreadsheet, acts like a database, and provides an API. It's often a good starting point before you need the full power of PostgreSQL.

Why it matters

If you're building anything that stores data, you're using a database. Understanding how tables, rows, and relationships work helps you structure your data properly from the start, which saves painful migrations later. It also helps you understand what's happening when an API call fails or returns unexpected results.

=++==+==++=