The UPDATE statement is used to change values in one, or more, or all of the records in a table.
UPDATE Project
SET ProjectName = 'Grindstone'
WHERE ProjectName = 'Hardwork';
(5 row(s) affected)
The UPDATE statement can be used in updating a single field in a table.
Note: The UPDATE doesn't generate a result set. If you want to know which records will be modified, first run a SELECT query that uses the same criteria. If the results are satisfactory, then run the update query.
UPDATE Products
SET ShippingWeight = '800lbs', ProductName = 'Grindstone MarkII', Price = '$348.71'
WHERE CatalogNumber = 'GS1097';
(1 row(s) affected)
The UPDATE statement can also be used to update more than one field in a table.
UPDATE MusicArtists
SET Instrument = 'violin'
WHERE Instrument = 'fiddle'
AND Style = 'classical';
(1 row(s) affected)
This example updates the 'MusicArtists' table by replacing any occurrence of the instrument 'fiddle' with 'violin' if the music type is 'classical'.
UPDATE TrainFares
SET Fare = Fare * 1.1
WHERE Line = 'Edinburgh'
AND Journey = 'single';
(4 row(s) affected)
This example updates the 'TrainFares' table to account for a 10% increase in the cost of a single ticket on the Edinburgh line.