Database Reference
In-Depth Information
Figure 8.12
REPLACE removes unspecified fields.
You may notice that we missed out the date on the last entry. If you have used the
UPDATE query, the temptation would be to run the following to add a date to the row:
REPLACE visitorbook (entryid, entrydate)
VALUES (7, '2002-02-20')
However, Figure 8.12 shows the results of this. Notice that instead of replacing the entry-
date field in the row, it has replaced the whole row, but only added the entrydate to the new
row that it has inserted. This shows the difference between UPDATE and REPLACE.
UPDATE can selectively change a field within a row, whereas REPLACE will delete the row
that it is replacing, and create a new row with only the fields that you specify.
So to add the date to the row we just added with REPLACE, we need to essentially run the
whole query again as follows:
REPLACE visitorbook ( entryid,
entrydate,
cookieid,
firstname,
familyname,
entrytext,
score,
location)
VALUES (7,
'2002-02-20',
1,
'Paul',
'Davis',
'How should I know?',
15,
'Dusseldorf')
Search WWH ::




Custom Search