Build Your Own DatabaseDriven Website Using PHP amp;amp; MySQL [Electronic resources]

Kevin Yank

نسخه متنی -صفحه : 190/ 118
نمايش فراداده

UPDATE

UPDATE [LOW_PRIORITY] [IGNORE] tbl_name
SET col_name=expr, ...
[WHERE where_definition]
[ORDER BY ...]
[LIMIT #]

The UPDATE query updates existing table entries by assigning new values to the specified columns. Columns that are not listed are left alone, with the exception of the TIMESTAMP column (see "TIMESTAMP[(M )] MySQL column types TIMESTAMP Description: A timestamp (date/time), in YYYYMMDD..."). The WHERE clause lets you specify a condition (where_definiton) that rows must satisfy if they are to be updated, while the LIMIT clause lets you specify a maximum number of rows to be updated.

Important

If WHERE and LIMIT are not specified, then every row in the table will be updated!

The ORDER BY clause lets you specify the order in which entries are updated. This is most useful in combination with the LIMIT clause—together they let you create queries like “update the 10 most recent rows”.

An UPDATE operation will fail with an error if the new value assigned to a row clashes with an existing value in a PRIMARY KEY or UNIQUE column, unless the IGNORE option is specified, in which case the query will simply have no effect on that particular row.

The LOW_PRIORITY option instructs MySQL to wait until there are no other clients reading the table before it performs the update.