为什么我不能在删除语句中使用别名呢?

时间:2022-11-10 22:48:35

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

在Visual Studio 2010的SQL Server Compact Edition中(可能是SQL Server或者一般的SQL Server,我不知道),这个命令可以工作:

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

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

但是这个命令在标识符f附近产生一个错误:error。

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

2 个解决方案

#1


157  

To alias the table you'd have to say:

要给表格添加别名,你必须说:

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

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语句的别名,特别是(至少是IIRC)这不再符合严格的ANSI。但是,正如评论所指出的,对其他查询形式(如相关性)来说,这是必要的。

#2


55  

The delete statement has strange syntax. It goes like this:

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

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

#1


157  

To alias the table you'd have to say:

要给表格添加别名,你必须说:

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

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语句的别名,特别是(至少是IIRC)这不再符合严格的ANSI。但是,正如评论所指出的,对其他查询形式(如相关性)来说,这是必要的。

#2


55  

The delete statement has strange syntax. It goes like this:

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

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