SQL UPDATE

SQL UPDATE statement to update table records with in database. You can update all table row or update data only matching conditionally WHERE clause.

SQL UPDATE All Rows

Syntax

UPDATE table_name 
    SET column_name1 = value1, column_name2 = value2, ...; 

Example Statement

SQL> UPDATE demo1 SET contact_no = 444;

10 rows updated.

SQL> select * from demo1;

 NO NAME              ADDRESS                        CONTACT_NO
--- ----------------- ------------------------------ -------------------
  1 Opal Kole         63 street Ct.                  000-444-8291
  2 Max Miller        41 NEW ROAD.                   000-444-8736
  3 Beccaa Moss       2500 green city.               000-444-8030
  4 Paul Singh        1343 Prospect St               000-444-8029
  5 Ken Myer          137 Clay Road                  000-444-7972
  6 Jack Evans        1365 Grove Way                 000-444-8845
  7 Reed Koch         1274 West Street               000-444-5672
  8 Gabe Hee          1220 Dallas Drive              000-444-5472
  9 Ben Mares         101 Candy Road                 000-444-6372
 10 Sariya Vargas                                    000-444-6371

10 rows selected.

UPDATE Conditionally use WHERE Clause

UPDATE table data only where WHERE Clause condition match. Use can optionally use LIMIT number to update only limited record starting from first.

Syntax

UPDATE table_name 
    SET column_name1 = value1, column_name2 = value2, ...
    [ WHERE condition ]
    [ LIMIT number]; 

Example

SQL> UPDATE demo1 SET ADDRESS = '10 Texo Court.' WHERE NO = 10;

1 row updated.

SQL> select * from demo1;

 NO NAME              ADDRESS                        CONTACT_NO
--- ----------------- ------------------------------ -------------------
  1 Opal Kole         63 street Ct.                  000-444-8291
  2 Max Miller        41 NEW ROAD.                   000-444-8736
  3 Beccaa Moss       2500 green city.               000-444-8030
  4 Paul Singh        1343 Prospect St               000-444-8029
  5 Ken Myer          137 Clay Road                  000-444-7972
  6 Jack Evans        1365 Grove Way                 000-444-8845
  7 Reed Koch         1274 West Street               000-444-5672
  8 Gabe Hee          1220 Dallas Drive              000-444-5472
  9 Ben Mares         101 Candy Road                 000-444-6372
 10 Sariya Vargas     10 Texo Court.                 000-444-6371            

10 rows selected.