在 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'))
要给表起别名,你必须说:
DELETE f FROM dbo.foods AS f WHERE f.name IN (...);
对于这么简单的语句,这样就可以了,并且不需要别名:
DELETE dbo.foods WHERE name IN (...);
但是,正如评论所暗示的那样,其他查询形式可能需要别名(例如任何与关联、连接、
EXISTS
等相结合的 DML)。在 SQL Server 中,您可以使用以下命令来执行此操作:
DELETE f
FROM dbo.foods AS f
INNER JOIN dbo.allergies AS a
ON f.FoodId = a.FoodId;
请记住,此查询可能必须在{而不是 SQL Server} 上以不同的方式构建。
删除语句的语法很奇怪。事情是这样的:
DELETE f FROM foods f WHERE (f.name IN ('chickens', 'rabbits'))