Go to: Articles List

SQL Basics Part 4 : Update Statement

The syntax for the Update statement is:

UPDATE TableName SET ColumnName1 = Value1 WHERE ColumnName2 = Value2

There are several things to note about this syntax example. If you do not supply a where clause the update will take effect on all records in the table. ColumnName1 and ColumnName2 can be the same column. Value1 and 2 should be enclosed in '' single quotes for strings and left out for integers.

Example:

UPDATE CustomerTable SET fname = 'Joe' WHERE lname = 'Doe'

This Update statement will set the fname equal to 'Joe' for all records that have the lname equal to 'Doe'. This poses a slight problem, how do you update records without damaging other ones. The answer to this problem is to have a certain column that does not change that you can use to change records from. Usually this field is an id number of some sort.