Slide 14.12: The WHERE clause (cont.)
  Slide 14.14: The DELETE statement
  Home


The UPDATE Statement


The UPDATE statement is used to modify the data in a table.

The syntax of updating a table is on the right.
 UPDATE  table_name
   SET  column_name = new_value
     WHERE  column_name = some_value

 LastName   FirstName   Address   City 
Hansen Ola Timoteivn 10 Sandnes
Svendson Tove Borgvn 23 Sandnes
Pettersen Kari Storgt 20 Stavanger
Rasmussen   Storgt 67  

 SQL> update  Persons  set  FirstName = 'Nina'
   2    where  LastName = 'Rasmussen';

 1 row updated.

 SQL> update  Persons
   2    set  Address = 'Stien 12', City = 'Stavanger'
   3    where  LastName = 'Rasmussen';

 1 row updated.

  • The first update adds a first name to the person with a last name of “Rasmussen.”
 LastName   FirstName   Address   City 
Hansen Ola Timoteivn 10 Sandnes
Svendson Tove Borgvn 23 Sandnes
Pettersen Kari Storgt 20 Stavanger
Rasmussen Nina Storgt 67  

  • The second update changes the address and add the name of the city.
 LastName   FirstName   Address   City 
Hansen Ola Timoteivn 10 Sandnes
Svendson Tove Borgvn 23 Sandnes
Pettersen Kari Storgt 20 Stavanger
Rasmussen Nina Stien 12 Stavanger



The following is an SQL test area from w3schools.com where the Customers table may be created by the following command:
   SQL> create table  Customers (
     2    CustomerID   varchar(16),
     3    CompanyName  varchar(32),
     4    ContactName  varchar(32),
     5    Address      varchar(64),
     6    City         varchar(32),
     7    PostalCode   varchar(16),
     8    Country      varchar(32) );
Note that the Customers table is for read only.