在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'))
答案 0 :(得分:190)
要为您必须说的表格添加别名:
DELETE f FROM dbo.foods AS f WHERE f.name IN (...);
我没有看到这个特定DELETE
语句的别名,特别是因为(至少IIRC)这不再符合严格的ANSI。但是,正如评论所暗示的那样,其他查询形式可能是必要的(例如相关性)。
答案 1 :(得分:64)
delete语句有很奇怪的语法。它是这样的:
DELETE f FROM foods f WHERE (f.name IN ('chickens', 'rabbits'))