-->ColdFusion 初级教程-->删除数据

ColdFusion

后页 前页
目录
北极星书库
删除数据


删除数据库中的数据可以由一个单独的文件完成,该文件包含一个执行SQL DELETE语句的CFQUERY标签。SQL DELETE语句的语法为:


DELETE FROM tablename


WHERE condition


WHERE从句控制删除语句删除一条记录,几条记录,或所有记录。


下面的例子从表Employees中删除一条记录:


DELETE FROM Employees


WHERE Employee_ID = 1


下面的例子从表Employees中删除几条记录。这个例子假设在销售部(Sales department)有不止一个员工:


DELETE FROM Employees


WHERE Department = ‘Sales’


下面的例子从表Employees中删除所有记录:


DELETE FROM Employees


注意,对数据库的删除操作是不可恢复的,因此要小心使用delete语句。


例子:执行删除操作的完整文件


<!--- 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>


后页
前页
目录
北极星书库