What Is an UPDATE?

The SELECT statement lets you retrieve sets of data from your tables. The UPDATE statement also works with sets of data, but you can use it to change the values in one or more columns and in one or more rows. By now, you should also be very familiar with expressions. To change a value in a column, you simply assign an expression to the column.

But you must be careful because UPDATE is very powerful. Most of the time you’ll want to update only one or a few rows. If you’re not careful, you can end up changing thousands of rows. To avoid this problem, we’ll show you a technique for testing your statement first.

Note

You can find all the sample statements and solutions in the “modify” version of the respective sample databases—SalesOrdersModify, ...

Get SQL Queries for Mere Mortals: A Hands-On Guide to Data Manipulation in SQL, Second Edition 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.