
Deleting Data
113
8
View deleteform.cfm a browser by specifying the page URL and an Employee ID,
for example, http://localhost/myapps/updateform.cfm?Emp_ID=3. and click the
Submit button.
The employee is deleted from the Employee table and the message displays.
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, you use the following code:
DELETE FROM Employee
Note
Deleting records from a database is not reversible. Use DELETE statements carefully.
Code
Description
<cfquery name="DeleteEmployee"
datasource="CompanyInfo">
DELETE FROM Employee
WHERE Emp_ID = #Form.Emp_ID#
</cfquery>
Delete 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 gets deleted.
<cfoutput>
You have deleted #Form.FirstName#
#Form.LastName# from the
Employees database.
</cfoutput>
Inform the user that the record was deleted.
Содержание COLDFUSION 5-DEVELOPING
Страница 1: ...Macromedia Incorporated Developing ColdFusion Applications MacroMedia ColdFusion 5 ...
Страница 58: ...38 Chapter 3 Querying a Database ...
Страница 134: ...114 Chapter 7 Updating Your Database ...
Страница 210: ...190 Chapter 10 Reusing Code ...
Страница 232: ...212 Chapter 11 Preventing and Handling Errors ...
Страница 238: ...218 Chapter 12 Using the Application Framework ...
Страница 262: ...242 Chapter 12 Using the Application Framework ...
Страница 278: ...258 Chapter 13 Extending ColdFusion Pages with CFML Scripting ...
Страница 320: ...300 Chapter 15 Indexing and Searching Data ...
Страница 336: ...316 Chapter 16 Sending and Receiving E mail ...
Страница 374: ...354 Chapter 18 Interacting with Remote Servers ...