liveBook · Manning

Database update

As explained in Learn SQL in a Month of Lunches

An UPDATE statement is an SQL statement that modifies values in existing rows of a table, optionally subject to filtering conditions.

A database update changes values already stored in a table. Think of it like correcting cells in a spreadsheet: the row stays in place, but one or more values change. An UPDATE statement names the table, SET assigns replacement values, and WHERE identifies the rows to change. section 17.1.2

Change one title’s price

To reduce the price of Pride and Predicates, update the title table, set Price to 8.95, and filter for its title name. The WHERE condition is crucial: without it, every row in title would receive the new price. section 17.1.2

UPDATE title
SET Price = 8.95
WHERE TitleName = 'Pride and Predicates';

This complete statement follows the practical order: choose the table, set a value, then limit the affected row. section 17.1.2

An UPDATE can handle several nearby tasks:

  • Set several columns at once by separating assignments with commas; all changed columns belong to the same table and meet the same filter condition. section 17.1.3
  • Use a key or other unique identifier, such as TitleID, to target the precise intended row or rows. section 17.1.3
  • Set a nullable column to NULL when the value should be absent rather than replaced with another value. section 17.1.3
  • Populate a newly added column in existing rows, using WHERE and IN to assign values to selected groups. section 18.2.1

For a change based on related tables, UPDATE still changes only one table, but a join can supply the filtering logic. The exact multitable UPDATE syntax differs among database products, so confirm the form supported by the RDBMS in use. section 17.1.4

Treat updates as permanent, real-time changes. Before running one, execute a SELECT with the same filtering logic and inspect the rows it returns. This preview helps catch a missing WHERE clause or incorrect predicate before data is changed. section 17.3 section 17.1.1

Correct a customer address

After adding a customer, update Address, City, State, and Zip together, filtering with CustomerID = 22. This is a realistic use of a unique identifier to change one customer record. section 17.5

How Learn SQL in a Month of Lunches covers it

How deep it goes
Explains basic and multiple-column updates, NULL assignments, validation, and multitable filtering while deferring vendor-specific multitable syntax to RDBMS documentation.
Examples
Uses title price and royalty changes, author middle-name removal, customer address correction, and CategoryID population.
What it assumes
Builds from familiar English phrasing and spreadsheet-like value changes while using tables, columns, and filtering conditions.
What you can do after
Apply it via SQL UPDATE statements to change selected rows after previewing matching data with SELECT.
How it connects
Connects UPDATE with WHERE predicates, SELECT validation, NULL, joins, key values, INSERT, and DELETE.

Also explained in

Compare how 3 books explain database update →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn SQL in a Month of Lunches. The section links point to the parts of the book it draws on.