SQL UPDATE Statement

  • The UPDATE statement updates data values in a database.
  • UPDATE can update one or more records in a table.
  • Use the WHERE clause to UPDATE only specific records.
The definitive guide
for data professionals


Order today!
 See 2 min video



The SQL UPDATE syntax


The general syntax is:
UPDATE table-name 
   SET column-name = value, column-name = value, ...

To limit the number of records to UPDATE append a WHERE clause:
UPDATE table-name 
   SET column-name = value, column-name = value, ...
 WHERE condition




SQL UPDATE Examples



Problem: discontinue all products in the database
UPDATE Product
   SET IsDiscontinued = 1

Note: the value 1 denotes true.

Results: 77 records updated.







Problem: Discontinue products over $50.
UPDATE Product
   SET IsDiscontinued = 1
 WHERE UnitPrice > 50

Note: the value 1 denotes true.

Results: 7 records updated.







Problem: Discontinue product with Id = 46.
UPDATE Product
   SET IsDiscontinued = 1
 WHERE Id = 46

This is a more common scenario in which a single record is updated.
Note: the value 1 denotes true.

Results: 1 record updated.





Problem: Supplier Norske Meierier (Id = 15) has moved: update their city, phone and fax.
UPDATE Supplier
   SET City = 'Oslo', Phone = '(0)1-953530', Fax = '(0)1-953555'
 WHERE Id = 15

This is a common scenario in which a single record is updated.


Results: 1 record updated.