为什么我不能在 DELETE 语句中使用别名? [英] Why can't I use an alias in a DELETE statement?

查看:42
本文介绍了为什么我不能在 DELETE 语句中使用别名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Visual Studio 2010 中的 SQL Server Compact Edition 中(一般来说可能是 SQL Server 和 SQL,我不知道),此命令有效:

In SQL Server Compact Edition in Visual Studio 2010 (maybe SQL Server and SQL in general, I don't know), this command works:

DELETE FROM foods WHERE (name IN ('chickens', 'rabbits'))

但是这个命令产生一个错误:Error near identifier f.期待输出.

but this command produces an error of: Error near identifier f. Expecting OUTPUT.

DELETE FROM foods f WHERE (f.name IN ('chickens', 'rabbits'))

推荐答案

要为表添加别名,您必须说:

To alias the table you'd have to say:

DELETE f FROM dbo.foods AS f WHERE f.name IN (...);

我没有看到这个特定 DELETE 语句的别名点,特别是因为(至少是 IIRC)这不再符合严格的 ANSI.但是是的,正如评论所暗示的那样,其他查询形式(例如相关性)可能是必要的.

I fail to see the point of aliasing for this specific DELETE statement, especially since (at least IIRC) this no longer conforms to strict ANSI. But yes, as comments suggest, it may be necessary for other query forms (eg correlation).

这篇关于为什么我不能在 DELETE 语句中使用别名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆