在我的ColdFusion 11网站(使用SQL Server 2008 R2)中,以下cfquery引发了上述错误:
<cfquery name="deleteGrantModificationItems" datasource="#dsource#">
DELETE col_key FROM myTable
WHERE col_key = <cfqueryPARAM value = "#appkey#" CFSQLType = "CF_SQL_VARCHAR">
</cfquery>
当我运行sql profiler来捕获查询时,我得到:
Declare @p1 int
Set @p1=NULL
exec sp_prepexec @p1 output,N'@P1 varchar(8000)',N'DELETE col_key FROM myTable
WHERE col_key = @P1 ','000000001644'
select @p1
当我在查询分析器中运行上述内容时,出现以下错误:
Msg 208, Level 16, State 1, Line 1
Invalid object name 'col_key'.
Msg 8180, Level 16, State 1, Procedure sp_prepexec, Line 1
Statement(s) could not be prepared.
我一直无法找到错误原因。
答案 0 :(得分:6)
您遇到语法错误,因为您应该使用DELETE FROM table_name ...
,如:
<cfquery name="deleteGrantModificationItems" datasource="#dsource#">
DELETE FROM myTable
WHERE col_key = <cfqueryPARAM value = "#appkey#" CFSQLType = "CF_SQL_VARCHAR">
</cfquery>
[WITH [,... n]] DELETE
[TOP(表达)[PERCENT]]
[FROM]