Learning Goals
By the end of this section you will:
understand the use of the UPDATE statement to change the values of an existing record
know how to write an UPDATE statement
The UPDATE statement is used to modify the existing records in a table.
Β
Summary
This video from W3Schools provides a tutorial on the SQL UPDATE statement, an essential tool for modifying existing records in a database.
A breakdown of the key concepts covered:
Functionality: The
UPDATEstatement is used to change data in a table. For instance, if a customerβs contact information changes, this command allows you to update their record.Syntax: The basic structure of the command is:
UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;Single and Multiple Record UpdatesL You can modify a single record by specifying a unique identifier in the
WHEREclause. To update multiple records, you can use a broader condition in theWHEREclause. For example, you could change the contact name for all customers in a specific country.The Importance of the
WHEREClause: The video strongly emphasizes the need to be careful with theWHEREclause. If you omit it, theUPDATEstatement will modify every single record in the table, which could lead to unintended data loss. Itβs recommended to first run aSELECTquery with the sameWHEREcondition to verify which rows will be affected before executing theUPDATE.
Go to the W3schools Tutorial on the UPDATE Statement and complete their exercises.
UPDATE Statement Activities
World Database
The city Brisbane has had a recent population update. Change its population to 2780063.
The city Bombay was renamed. Update its name to Mumbai.
The percentage of Spanish speakers in ESP (Spain) was incorrectly recorded. Change it to 92.0
Shares Database
Update the long name of the Computer industry (Code 3573) to Computer Hardware & Peripherals.
The client Debra Parker, born on 1957-10-10, has moved to Brisbane. Update her city.
Reduce the PurPrice by 10% for the holding with the most recent PurDate.
Chinook Database
Set support rep to Jane Peacock for all Brazilian customers
Increase unit price by 0.20 for all Rock tracks