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

Instruction

Great! Now that you know how to add data to the database, it's time to learn how to modify existing data.

If you want to change the Name of the user with ID 7, you can use the command:

UPDATE User 
SET Name = N'Elizabeth'
WHERE Id = 7;

Here, User is the modified table, Name is the modified column, and N'Elizabeth' is the new value of the column. The WHERE condition tells the database which rows should be modified, and it can be any condition you'd write in a SELECT clause. (Remember that you can always go to the SQL Basics in MS SQL Server course for more information).

After you run the query, the Name for the User with Id 7 will be set to N'Elizabeth'. Piece of cake!

Exercise

The owners of the restaurant complain that the item with ID 2 sells poorly. This might be because Spring Scrolls don't really sound like something particularly edible.

Correct the Name by changing it to Spring Rolls.

Stuck? Here's a hint!

Type:

UPDATE Dish 
SET Name = N'Spring Rolls' 
WHERE Id = 2;