Database fundamentals

Tables, rows, and columns

Connect the relational model to the tables, rows, and columns you work with in a SQL database.

8 minute lesson

~~~

A relational database stores related facts in tables. A table should describe one kind of thing, such as a customer, order, or product.

Consider this orders table:

idcustomer_emailstatustotal
101[email protected]paid49.00
102[email protected]pending18.50

Each horizontal row is one order. Each column describes one attribute shared by every order. The value at one row and column is sometimes called a field or cell.

The schema exists before the data. It says that id identifies the row, customer_email contains text, status accepts the chosen representation, and total stores an exact amount.

That structure lets SQL ask useful questions:

SELECT id, total
FROM orders
WHERE status = 'paid';

The result contains order 101, because that row makes the condition true.

A row needs a stable identity. Names and email addresses can change or repeat, so databases normally use a primary-key column such as id. The key lets an update target one order without depending on mutable business data.

Do not put several independent values into one cell. A comma-separated list of product IDs cannot be constrained or joined like real rows. Related facts belong in related tables, which we will model later.

Your action is to sketch a books table with four columns. Mark the primary key, choose one required column, and write two example rows. Then explain what one row represents.

Lesson completed

Take this course offline

Get every free book and course as PDF and EPUB files.

Get the download library →