Database Reference
In-Depth Information
Tip
The
IGNORE
Keyword If your
UPDATE
statement updates multiple rows and an
error occurs while updating one or more of those rows, the entire
UPDATE
operation is
cancelled (and any rows updated before the error occurred are restored to their original
values). To continue processing updates, even if an error occurs, use the
IGNORE
key-
word, like this:
UPDATE IGNORE customers ...
To delete a column's value, you can set it to
NULL
(assuming the table is
defined to allow
NULL
values). You can do this as follows:
▼
Input
UPDATE customers
SET cust_email = NULL
WHERE cust_id = 10005;
Here the
NULL
keyword is used to save no value to the
cust_email
column.
To delete (remove)
data from a table, the
DELETE
statement is used.
DELETE
can be used in two ways:
To delete specific rows from a table
■
To delete all rows from a table
■
We now take a look at each of these.
Caution
Don't Omit the
WHERE
Clause Special care must be exercised when using
DELETE
because it is all too easy to mistakenly delete every row from your table. Please read
this entire section on
DELETE
before using this statement.
Tip
DELETE
and Security Use of the
DELETE
statement can be restricted and con-
trolled. More on this in Chapter 28.
I already stated that
UPDATE
is easy to use. The good (and bad) news is that
DELETE
is even easier to use.
The following statement deletes a
single row from the
customers
table: