Java Reference
In-Depth Information
Common Programming Error 24.4
It's normally an error to specify a value for an autoincrement column.
AuthorID
FirstName
LastName
1
Paul
Deitel
2
Harvey
Deitel
3
Abbey
Deitel
4
Dan
Quirk
5
Michael
Morgano
6
Sue
Red
Fig. 24.20
|
Sample data from table
Authors
after an
INSERT
operation.
UPDATE
tableName
SET
columnName1
=
value1
,
columnName2
=
value2
, …,
columnNameN
=
valueN
WHERE
criteria
where
tableName
is the table to update. The
tableName
is followed by keyword
SET
and a
comma-separated list of
columnName
=
value
pairs. The optional
WHERE
clause provides
criteria that determine which rows to update. Though not required, the
WHERE
clause is
typically used, unless a change is to be made to every row. The
UPDATE
statement
UPDATE
Authors
SET
LastName = 'Black'
WHERE
LastName = 'Red'
AND
FirstName = 'Sue'
updates a row in the
Authors
table. The statement indicates that
LastName
will be assigned
the value
Black
for the row where
LastName
is
Red
and
FirstName
is
Sue
. [
Note:
If there
are multiple matching rows, this statement will modify
all
such rows to have the last name
“Black.”] If we know the
AuthorID
in advance of the
UPDATE
operation (possibly because
we searched for it previously), the
WHERE
clause can be simplified as follows:
WHERE
AuthorID = 6
Figure 24.21 shows the
Authors
table after the
UPDATE
operation has taken place.
AuthorID
FirstName
LastName
1
Paul
Deitel
2
Harvey
Deitel
3
Abbey
Deitel
4
Dan
Quirk
5
Michael
Morgano
6
Sue
Black
Fig. 24.21
|
Sample data from table
Authors
after an
UPDATE
operation.