我需要从表中删除一些其他相似表中不可用的行。我可以使用这段代码正确选择要删除的行

SELECT *
FROM [DB01].[forward].[forward_value] as DB01
WHERE Id_forward like 'test' and
NOT EXISTS (SELECT *
    FROM [DB02].[db_marketdata].[forward].[forward_value] as DB02
    WHERE DB01.Id_Forward = DB02.Id_Forward and
        DB01.Id_Block = DB02.Id_Block and
        DB01.Id_PriceType = DB02.Id_PriceType and
)

当我将SELECT (*)更改为DELETE时,出现错误,因为我无法为第一个表加上别名。

消息156,第15级,状态1,第2行
关键字“ as”附近的语法不正确。

如何在不使用别名正确选择行的情况下删除这些值?

最佳答案

将您的别名使用DELETE语法,如下所示:

delete DB01
FROM [DB01].[forward].[forward_value] as DB01
WHERE Id_forward like 'test' and
NOT EXISTS (SELECT *
    FROM [DB02].[db_marketdata].[forward].[forward_value] as DB02
    WHERE DB01.Id_Forward = DB02.Id_Forward and
        DB01.Id_Block = DB02.Id_Block and
        DB01.Id_PriceType = DB02.Id_PriceType
)

09-25 22:12