designwithfocus

Data & databases

What Is a Relational Database? Tables, Keys and SQL

By Design With Focus Team 6 min read
Database table sketch with rows, columns, a key mark, and a join between two tables

Short answer

A relational database stores data in tables, and a relation is the mathematical name for one of those tables. Each table is rows that share the same named columns, and each column has a data type. SQL reads and changes those tables. A primary key uniquely identifies a row and cannot be null. Joins pair rows from more than one table.

Last verified against the sources listed below.

Key takeaways

  • PostgreSQL's tutorial says a relation is a mathematical term for a table.
  • Each row in a table has the same named columns, and SQL does not promise row order.
  • A primary key uniquely identifies a row, must be unique and not null, and a table has at most one.
  • A foreign key requires values to match a row in another table.
  • A join query pairs rows from two tables, or from one table used twice.
  • PostgreSQL also describes hierarchical and object-oriented databases as other ways to organize data.

People who type what is relational database are usually trying to picture tables, keys, and the queries that connect them. PostgreSQL’s concepts tutorial answers the first part directly. PostgreSQL is a relational database management system, which means it manages data stored in relations, and a relation is essentially a mathematical term for a table.

Other organizations exist. That same page names files and directories on Unix-like systems as a hierarchical database, and the object-oriented database as a later development. The sections below stay with the relational shape PostgreSQL documents: tables, keys, joins, and SQL.

What is a table in this kind of database?

A table is a named collection of rows that share one set of columns. The concepts page says each row has the same named columns, each column has a data type, and SQL does not guarantee row order unless a query sorts them. Tables are grouped into databases, and the databases managed by one PostgreSQL server instance are a database cluster.

The table basics chapter compares this to a paper table. Column count and order are fixed, each column has a name, and the row count changes as you store data. A numeric column rejects arbitrary text and can be used in calculations, while a text column accepts much more and is a poor fit for math.

You create one with CREATE TABLE, naming the table, the columns, and each type. The chapter’s example uses product_no integer, name text, and price numeric. DROP TABLE removes it. Column count is limited to somewhere between 250 and 1600, depending on types, and that page calls a table near that width a questionable design.

How do rows, columns, and keys work?

Rows hold the values and columns name them. Table basics says SQL assigns no unique id, so identical rows are possible until you add a constraint. The constraints chapter shows how.

A primary key is the column or columns that identify a row, and the values must be unique and not null. It matches UNIQUE plus NOT NULL, creates a unique B-tree index, and a table has at most one. Theory says every table should have one. PostgreSQL does not enforce that.

A foreign key requires values to match a row in another table. In the orders example, a product number must exist on the products table unless it is null.

Piece What PostgreSQL says it is
Table Named rows, also called a relation
Row One entry sharing that table’s columns
Column A named, typed field in a fixed set
Primary key Unique non-null id, one per table
Foreign key Values that must match another table

How does a join combine tables?

A join pairs rows from more than one table using an expression you supply. The joins tutorial defines a join as a query that reads multiple tables at once, or the same table more than once. An expression says which rows pair. The weather example matches weather.city to cities.name.

An inner join drops unmatched rows, so a city that appears only in the weather table disappears. A left outer join keeps every left-hand row and writes nulls on the right when nothing matches. The tutorial also names right and full outer joins, plus a self join that compares a table to itself under two aliases.

JOIN with ON arrived in SQL-92. The older form lists tables in FROM and puts the comparison in WHERE, and the page says the results match. SELECT * concatenates both sides, so list the columns you want and qualify names that both tables use.

How is this different from other databases?

PostgreSQL’s tutorial contrasts tables with other organizations, not with a price list. Neither alternative is described there as tables linked by keys:

  • Files and directories on a Unix-like system are the hierarchical example.
  • An object-oriented database is the other organization the page names.
  • A relation, meaning a table, is the shape this article stays with.

Python’s sqlite3 documentation describes SQLite as a C library for a disk-based database that needs no separate server process and uses a nonstandard variant of SQL. People prototype with it and later port to a larger database such as PostgreSQL. That is a difference in how the database runs, not a second kind of table.

MDN’s server-side introduction shows the website case. Most large sites pull database rows into HTML templates, while a static site returns the same hard-coded content for a resource. The database is what lets one template serve many rows.

What does SQL do with these tables?

SQL is the language PostgreSQL uses and extends to define tables and ask questions. The about page calls it a free, open source object-relational system. The project dates to 1986, it has been ACID-compliant since 2001, and the version 19 release in November 2026 conforms to at least 170 of the 177 mandatory features for SQL:2023 Core. The page says no relational database meets full conformance.

CREATE TABLE defines columns and types, constraints add keys, and SELECT with JOIN reads related rows. Extra types such as arrays, UUID, and JSON still live inside tables. They do not replace rows and columns. A W3C recommendation from 27 September 2012 maps relational data to RDF so tables can be shared as linked data, and that mapping assumes this shape.

Why do these examples use underscores?

The PostgreSQL examples spell multi-word column names with underscores, and a converter produces that spelling. You will see product_no, first_column, temp_lo, and temp_hi in the tutorials. The docs say to pick a consistent pattern, and they do not declare one universal style.

The snake_case converter turns a phrase into that underscore form, a common style for SQL column names and a match for these examples.

A site that shows the rows still needs layout and type, which is separate from the table that stores the words. Web design is that planning, not the database.

The picture to keep is a paper table. Columns are typed headings, rows have no promised order, a primary key finds one row, a foreign key points at another table, and a join is the query that follows that pointer.

Frequently asked questions

Does SQL keep rows in the order you inserted them?

No. Both the concepts tutorial and the table basics chapter say SQL does not guarantee the order of rows. When you read a table, rows appear in an unspecified order unless the query asks for sorting. Columns do have a fixed order, and each column has a name and a data type. If a screen shows rows in insert order, that is the query or the client, not a promise the table itself makes. Ask for the order you need every time the order matters.

Can two rows be completely identical?

Yes, until you add a constraint. The table basics chapter says SQL does not assign unique identifiers to rows, so several identical rows are allowed. That follows from the mathematical model, and the chapter calls it usually undesirable. A primary key, described in the constraints chapter, forces the key columns to be unique and not null. A unique constraint can also keep a column or a group of columns from repeating. Without one of those, the table will accept the duplicate.

How many columns can a PostgreSQL table hold?

The table basics chapter says the limit depends on the column types and falls between 250 and 1600. It also says a table anywhere near that width is highly unusual and often a questionable design. The fix it points at is not a bigger row. It is a different table shape. Everyday types named on that page include integer, numeric, text, date, time, and timestamp. Users can define their own types as well. Width and type are separate choices.

What is a database cluster in PostgreSQL?

The concepts tutorial uses cluster for a collection of databases managed by a single PostgreSQL server instance. Tables are grouped into databases, and those databases sit inside the cluster. The word here is not a pile of separate machines. It is the instance and the databases it manages. The about page adds that PostgreSQL has been ACID-compliant since 2001 and that its origins go back to 1986 and the POSTGRES project at the University of California at Berkeley.

What does a left outer join keep that an inner join drops?

The joins tutorial says an inner join ignores unmatched rows. In its weather example, Hayward disappears because the cities table has no Hayward row. A left outer join keeps every row from the left table and fills the right-hand columns with nulls when nothing matches, so Hayward comes back with an empty location. The page also names right outer joins and full outer joins, and it shows a self join, which uses the same table twice under two names.

Sources