May 2019
Intermediate to advanced
542 pages
13h 37m
English
To update existing rows in a table, you use the UPDATE statement, like so:
UPDATE coffees SET roast_id = 4 WHERE id = 2;
The SET clause is followed by a list of value assignments for the fields you want to change, and the WHERE clause describes conditions that must be true if a particular row is to be updated. In this case, we're going to change the value of the roast_id column to 4 for the record where the id column is 2.
SQL uses a single equals sign for both assignment and equality operations. It does not ever use the double-equals sign that Python uses.
Update operations can also affect multiple records, like this:
UPDATE coffees SET roast_id = roast_id + 1 WHERE coffee_brand LIKE 'Strawbunks';
In this case, we're ...
Read now
Unlock full access