System information
130 Chapter 12: Lesson 9: Enabling Database Maintenance
The SQL DELETE statement removes existing rows in a relational table. The DELETE
statement has the following format:
DELETE FROM table_name WHERE column_name = some_value
For example, the database table named Clients contains holds information about people, in the
following rows:
To delete everyone from New York from the table, use the following statement:
DELETE FROM Clients WHERE City = 'New York'
After the database management system processes the preceding statement, the table contains the
following row only:
To ensure that the Trip Maintenance application deletes only the proper trip, you must use the
unique
tripID key when issuing the SQL DELETE statement. The RecordID field holds the
tripID. Using the hidden RecordID input tag from the Trip Detail page, the following SQL
statement deletes a row from the Trips table:
DELETE FROM trips WHERE tripID = #Form.RecordID#
To enable users to delete trips:
1.
Open the maintenanceaction.cfm file in the my_app directory in your editor.
2.
Add the highlighted code in the file.
<cfif IsDefined("Form.btnSearch")>
<!--- Code to execute if the user clicked Search. --->
<cflocation url=”tripsearchform.cfm”>
<cfelseif IsDefined("Form.btnDelete")>
<!--- Code to execute if the user clicked Delete. --->
<cfquery name="DeleteRecord" datasource="CompassTravel">
DELETE FROM trips WHERE tripID = #Form.RecordID#
</cfquery>
<cflocation url="tripdetail.cfm">
<cfelseif IsDefined("Form.btnEdit")>
<!--- Code to execute if the user clicked Edit. --->
<cfelseif IsDefined("Form.btnAdd")>
<!--- Code to execute if the user clicked Add. --->
</cfif>
3.
Save the page.
LastName FirstName Address City
Jones Tom 50 Main St New York
Adamson Anita 521 Beacon St Boston
Green Peter 1 Broadway New York
LastName FirstName Address City
Adamson Anita 521 Beacon St Boston