Updating multiple values
You can run the following to do so and then verify all cities are NULL. You can easily adjust the values using the following statement: However, suppose the sales department want a record of all changes.
Once you look at the statement you’ll see we added FROM and INNER JOIN clauses. Sure, you could run a query before the update, one after the update, and then compare, but rather than doing all of that we can use the OUTPUT clause to log the changes directly into a table.
The UPDATE statement is capable of updating more than one row. All rows returned via the WHERE clause criteria are updated.
Notice we used the primary key Sales Person ID to filter the row.
You can get started using these free tools using my Guide Though this article uses the Adventure Works database for its examples, I’ve decided to create an example table for use within the database to help better illustrate the examples. Also, let’s initially populate the table with some data using the following INSERT statement: You can learn more about the INSERT statement by reading our article Introduction to the INSERT Statement.
The UPDATE statement is used to change column values.
This makes is really easy to ensure we are updating exactly one row.
Note: The Sales Person ID generated for your table’s rows may be different than what is show in the exercises, since this primary key is auto generated.
Search for updating multiple values:
To update the rows to reflect this we could use this UPDATE statement: Which results in the following row modifications: The UPDATE statement is complex and there are many elements to consider. For a full list check out the UPDATE (Transact-SQL) article.