Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
Inserting data
Modifying data
10. Modify multiple rows
Deleting data
CRUD

Instruction

Excellent! When you write an UPDATE query, the database modifies all rows for which the WHERE condition is true. You can modify many rows with one UPDATE command. You can build up your WHERE condition with AND, OR, and NOT. You can also use any other condition you would use in a SELECT command.

To change the Age value for all users with an Id lower than 4, you can run the command:

UPDATE User 
SET Age = 17 
WHERE Id < 4; 

The database always tells you how many rows have actually been modified. In the previous examples, it only modified a single row each time. Always check the number of modified rows to see if your query did what you expected it to.

Exercise

It's happy hour at our restaurant! Change the price of all main courses to 20.

Stuck? Here's a hint!

Type:

UPDATE Dish 
SET Price = 20 
WHERE Type = N'main course';