BackUp LevelNext

Deleting Data

Deleting data in a database can be done with a single delete page. The delete page contains a CFQUERY tag with a SQL delete statement.

Syntax

The syntax for a SQL delete statement is:

DELETE FROM tablename
WHERE condition

The condition controls whether or not the delete statement deletes a single record, several records, or all records.

Example: Deleting a single record

The following example demonstrates deleting a single employee from the Employees table.

DELETE FROM Employees
WHERE Employee_ID = 1

Example: Deleting several records

The following example demonstrates deleting several records from the Employee table. The example assumes that there are several Employees in the sales department.

DELETE FROM Employees
WHERE Department = 'Sales'

Example: Deleting all records

The following example demonstrates deleting all the records from the Employees table.

DELETE FROM Employees

Note

Deleting records from a database is not reversible. Use delete statements carefully.

Example: Complete delete page

<!--- Page to delete single employee record --->
<CFQUERY NAME="DeleteEmployee"
    DATASOURCE="Employee DB">
    DELETE FROM Employees
    WHERE Employee_ID = #URL.EmployeeID#
</CFQUERY>

<HTML>
<HEAD>
    <TITLE>Delete Employee Record</TITLE>
</HEAD>
<BODY>
<H3>The employee record has been deleted.</H3>

</BODY>
</HTML>

BackUp LevelNext

allaire

AllaireDoc@allaire.com
Copyright © 1998, Allaire Corporation. All rights reserved.