User Guide

Table Of Contents
488 Chapter 21: Updating Your Database
Reviewing the code
The following table describes the code and its function:
Deleting multiple records
You can use a SQL condition to delete several records. The following example deletes the records
for everyone in the Sales department (which has Dept_ID number 4) from the Employee table:
DELETE FROM Employee
WHERE Dept_ID = 4
To delete all the records from the Employee table, use the following code:
DELETE FROM Employee
Caution: Deleting records from a database is not reversible. Use DELETE statements carefully.
Code Description
<cfquery name="DeleteEmployee"
datasource="cfdocexamples">
DELETE FROM Employee
WHERE Emp_ID = #Form.Emp_ID#
</cfquery>
Deletes the record in the database whose Emp_ID
column matches the Emp_ID (hidden) field on the form.
Since the Emp_ID is the table’s primary key, only one
record is deleted.
<cfoutput>
You have deleted #Form.FirstName#
#Form.LastName# from the
employee database.
</cfoutput>
Informs the user that the record was deleted.