Updating rows, deleting rows, and more WHERE clauses

To update or delete existing rows, we use the UPDATE and DELETE FROM keywords in conjunction with a WHERE clause to select the affected rows.

Deleting is fairly simple looks like this:

DELETE FROM instruments WHERE id=4;

The DELETE FROM command will delete any rows that match the WHERE conditions. In this case, we match the primary key to ensure only one row is deleted. If no rows match the WHERE conditions, no rows will be deleted. Note, however, that the WHERE clause is technically optional: DELETE FROM instruments will simply delete all rows in the table.

Updating is similar, except it includes a SET clause to specify new column values as follows:

UPDATE musicians SET main_instrument=3 ...

Get Python GUI Programming with Tkinter now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.