Database Management · Beginner level

Beginner level · Module 1: Relational Databases and First Queries · Lesson 3 of 3

Reading and Changing Data

Use SELECT to read data and INSERT, UPDATE and DELETE to change it — safely.

In this lesson you will

  • Write SELECT statements with column lists
  • Insert, update and delete rows using WHERE safely

Key concepts

SELECTINSERT INTO … VALUESUPDATE … SET … WHEREDELETE … WHERE

The lesson

SELECT title, author FROM books; reads two columns from every row. SELECT * reads every column — convenient for exploring, but name the columns in real queries so results are predictable.

INSERT INTO books (title, author, year) VALUES ('Things Fall Apart', 'Chinua Achebe', 1958); adds a row. Name the columns so the statement keeps working if the table changes.

UPDATE books SET year = 1959 WHERE id = 3; changes one row. Without WHERE, UPDATE and DELETE affect every row in the table. Always run the matching SELECT with the same WHERE first, to see exactly which rows will change.

Step by step

  1. Insert ten books.
  2. Select different column combinations.
  3. Run a SELECT with a WHERE, then the UPDATE with the same WHERE.
  4. Delete one book safely the same way.

Practice activity

Complete the library practical activity, recording every statement in your SQL file.

Expected result: The table holds the correct books after all changes, and every UPDATE and DELETE uses a tested WHERE clause.

Check your understanding

  1. What happens if you run DELETE FROM books; without WHERE?

    Show answer

    Every row in the table is deleted.

  2. Why name columns in an INSERT?

    Show answer

    The statement keeps working correctly if the table's columns change or are reordered.

Taught live by an instructor — online or in person. Free course lessons are for self-study and do not lead to a certificate — see registration options.