Полезная информация

next up previous contents index
Next: Sorting Data with ORDER Up: Five Basic SQL Commands Previous: Removing Data with DELETE

Modifying Data with UPDATE

How do you modify data already in the database? You could use DELETE to remove the row, then INSERT to insert an new row, but that is quite inefficient. The UPDATE command allows you to update data already in the database. It follows a format similar to the previous commands.

Mike had a birthday, so we want to update his age in this table. Figure [*] shows an example.

  
Figure: My first UPDATE
\begin{figure}\begin{list}{}{
\setlength{\rightmargin}{\leftmargin}
\raggedrigh...
...vert Tampa~~~~~~~~~~\vert FL~~~\vert~20
\par (3~rows)\end{list}\par
\end{figure}

The example shows the word UPDATE, the table name friends, followed by SET, then the column name, equals sign (=), and the new value. The WHERE clause restricts the number of rows affected by the update, as in DELETE. Without a WHERE clause, all rows are updated.

Notice that the Mike row has moved to the end of the list. The next section will show you how to control the order of the row display.


Bruce Momjian
1999-11-21