Pordalibreqs

FREE KIT / DATABASE FOUNDATIONS

A first look at relational data.

A short introductory reading guide. No sign-up or payment required.

1. Think in tables

A table groups records of one kind. In a small library, a books table might store one row per book. Each column describes one attribute of that book.

book_idtitleauthor_id
1River Notes10
2The Quiet Map20
3Winter Pages10

There are three rows and three columns. The title column describes the book; book_id identifies its row.

2. Give each record an identity

A primary key uniquely identifies a row. Titles can repeat or change, so a separate book_id can make a more stable identifier. A primary key cannot contain duplicate values or NULL.

The author_id column can refer to a row in a separate authors table. Two books may refer to the same author without repeating all the author’s details. A foreign key constraint can require that referenced author to exist.

3. Ask a small question

SELECT title
FROM books
WHERE author_id = 10
ORDER BY title;

SELECT chooses the title column. FROM chooses the books table. WHERE keeps rows with author_id equal to 10. ORDER BY sorts the result by title. In this example, the result contains River Notes and Winter Pages.

4. Distinguish a value from a missing value

NULL represents a missing or unknown value, not an empty string or zero. To find a missing author reference, use IS NULL rather than = NULL. Whether a column permits NULL is part of the table design.

5. Try it on paper

  1. Which column identifies one book?
  2. How many books refer to author 10?
  3. Change the query to show books by author 20.
  4. Why might storing an author’s name in every book row cause maintenance problems?
Review the answers

1. book_id. 2. Two books. 3. Use WHERE author_id = 20; the title is The Quiet Map. 4. A name correction would need to be repeated across multiple rows and could become inconsistent.

6. Continue with care

Use small practice datasets as you explore. SELECT reads data; UPDATE and DELETE can change or remove it. Learn filtering and transactions before modifying important records. Database systems differ, so check syntax against your chosen system’s documentation.

See Arc Guide ↗