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.
![]() |
To delete one record from a database: |
updateform.cfm
in Studio.
<FORM ACTION="deletepage.cfm" METHOD="Post">
deleteform.cfm
.
<CFQUERY NAME="DeleteEmployee" DATASOURCE="CompanyInfo"> 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>
deletepage.cfm
.
deleteform.cfm
in a browser, enter values, and click the Submit button.
The employee is deleted from the Employees table and the message appears.
To delete several records, you would specify a condition. The following example demonstrates deleting the records for everyone in the Sales department from the Employee table. The example assumes that there are several Employees in the sales department.
DELETE FROM Employees WHERE Department = 'Sales'
To delete all the records from the Employees table, you would use the following:
DELETE FROM Employees
Note | Deleting records from a database is not reversible. Use delete statements carefully. |