UPDATE is an SQL command for modifying data in a table in a (relational) database. Here is an example:

UPDATE example SET firstname='Tom', lastname='Smith' WHERE nickname='hax0r'

The statement above tells the database to modify all rows where the field nickname has the value 'hax0r' (a string) in the table called example. In all these rows, the field firstname is changed to 'Tom', and lastname is changed to 'Smith'. All fields that are not mentioned are left unchanged.

The WHERE clause is the same as the one used by SELECT and DELETE. If the WHERE clause is omitted, then all rows in the table are modified.

Here are some things that can cause the update to fail:

  • Modifying a field that is part of a primary key or a unique index, and there is another row in the table with the same values as the new values of the modified row. See also: Key violation
  • There are one ore more foreign keys defined on one or more of the modified fields, and there is no record with the new key value in the referenced table.
  • Another table references the data in the table through a foreign key, and the foreign key does not cascade updates. The update only fails if the key value(s) are changed and there are rows in the referencing table with the same key values as the old key values.
  • The user does not have permission to modify data in the table.

Log in or register to write something here or to contact authors.