7.4. Updates and Deletes

Up to now you have seen how to create tables, how to insert records, and how to select data. In this section you will learn to modify data and to remove records from a table.

To modify data, SQL provides a command called UPDATE. The next listing shows the syntax overview of the UPDATE command:

phpbook=# \h UPDATE
Command:     UPDATE
Description: update rows of a table
Syntax:
UPDATE [ ONLY ] table SET col = expression [, ...]
    [ FROM fromlist ]
    [ WHERE condition ]

UPDATE can be used to modify a list of columns. Just like SELECT statements, UPDATE statements can contain WHERE clauses for restricting the data modified by the UPDATE query.

Take a look at a simple UPDATE operation:

phpbook=# UPDATE t_person SET city='Mauerbach' ...

Get PHP and PostgreSQL: Advanced Web Programming 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.