(SQL) UPDATE: Changing an Existing Row/Record
(Substantially borrowed from W3Schools)
The UPDATE statement is used to modify the existing records in a table.
UPDATE Syntax
UPDATE table_name SET column1 = value1, column2 = value2, ... WHERE condition;
Note: Be careful when updating records in a table! Notice the WHERE clause in the UPDATE statement. The WHERE clause specifies which record(s) that should be updated. If you omit the WHERE clause, all records in the table will be updated!
Example
UPDATE Customers SET ContactName = 'Alfred Schmidt', City= 'Frankfurt' WHERE CustomerID = 1
Note: The WHERE clause identifies a single record because CustomerID is UNIQUE
. Some other times you want to update several records at once. For instance, the following SQL statement will update/change the ContactName to Juan
for all records where country is Mexico
:
UPDATE Customers SET ContactName='Juan' WHERE Country='Mexico';