196

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

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

但是此命令会产生以下错误:Error near identifier f. Expecting OUTPUT.

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

2 回答 2

286

要给表起别名,您必须说:

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

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

于 2012-06-12T21:36:43.670 回答
89

delete 语句有奇怪的语法。它是这样的:

DELETE f FROM foods f WHERE (f.name IN ('chickens', 'rabbits'))
于 2012-06-12T21:37:06.950 回答