Here we look at the Update command in SQL.
The Update command in SQL allows us to update data in a database table, where data already exists and we would like to change some of it.
You can change just one row or you can modify multiple rows at the same time.
In the following example, we look at the table called Customers. We use the Update command to change the telephone number of every row whose name value is Fred, thus every Fred will have the same phone number now.
-- Update all Customers called Fred to have telephone number 55555
UPDATE Customers SET Telephone = '55555' WHERE Name = 'Fred'
If you want to update more than one column, just specify the name of each column seperated by commas, and provide a value which will be entered.
The following example continues from the first example by changing the mobile as well as the telephone value, and also only changes the details of rows who name is Fred but only where the company value is World Ltd as well.
-- Update all Customers called Fred and from the company called World Ltd
-- to have telephone number 55555 and a mobile number of 77777
UPDATE Customers SET Telephone = '55555', Mobile = '77777'
WHERE Name = 'Fred' AND Company = 'World Ltd'