Deleting Data; Deleting A Single Record - MACROMEDIA COLDFUSION 5-DEVELOPING Develop Manual

Table of Contents

Advertisement

112

Deleting Data

You use a

Deleting a single record

To delete a single record, use the table's primary key in the WHERE condition of a
SQL DELETE statement. In the example, the Emp_ID field is the primary key, so the
SQL Delete statement is as follows:
DELETE FROM Employee WHERE Emp_ID = #Form.Emp_ID#
You often want to see the data before you delete it. The following example displays
the data to be deleted by reusing the form page used to insert and update data. Any
data that you enter in the form before submitting it is not used, so you can use a table
to display the record to be deleted instead.
To delete one record from a database:
1
2
3
4
5
6
7
tag with a SQL DELETE statement to delete data from a database.
cfquery
Open the file updateform.cfm in ColdFusion Studio.
Change the title to "Delete Form" and the text on the submit button to "Delete
Record".
Change the
tag so that it appears as follows:
form
<form action="deleteaction.cfm" method="Post">
Save the modified file as deleteform.cfm.
Create a new application page in ColdFusion Studio.
Enter the following code:
<cfquery name="DeleteEmployee"
datasource="CompanyInfo">
DELETE FROM Employee
WHERE Emp_ID = #Form.Emp_ID#
</cfquery>
<html>
<head>
<title>Delete Employee Record</title>
</head>
<body>
<h3>The employee record has been deleted.</h3>
<P><cfoutput>
You have deleted #Form.FirstName# #Form.LastName# from the Employees
database.
</cfoutput></P>
</body>
</html>
Save the page. as deleteaction.cfm.
Chapter 7 Updating Your Database

Advertisement

Table of Contents
loading

This manual is also suitable for:

Coldfusion 5

Table of Contents