User Guide

128 Chapter 10: Lesson 6: Adding and Updating SQL Data
9 Test update logic by opening the tripdetail.cfm page in your browser and doing the following
tasks:
a Click the Edit button.
b Double the price of the current trip.
c Click Save.
The ColdFusion
cfupdate works well for updating a single record. To update several records in a
single query, you must use the SQL UPDATE statement in conjunction with
cfquery.
SQL Update
The SQL UPDATE statement updates or changes rows in a relational table. The syntax of the
UPDATE statement is as follows:
UPDATE table_name SET column_name = new_value
WHERE column_name = some_value
Consider a database table named Clients that contains information about people in the following
rows:
After the following SQL statement executes:
UPDATE Clients SET LastName =’Pitt’
WHERE ID = 3
the table contains the following rows:
Update several rows
The UPDATE statement updates all rows that meet the criteria found in the WHERE clause. If
there is no WHERE clause, every row of the table is updated. After the following SQL statement
executes:
UPDATE Clients SET Age = Age + 1
WHERE ID = 3
PersonID LastName FirstName Age
1GreenTom12
2WallPeter42
3 Madigan Jess 20
PersonID LastName FirstName Age
1GreenTom12
2WallPeter42
3PittJess20