从别名 table 中删除无效(但 select 有效)
Delete from aliased table doesn't work (but select does)
我需要从 table 中删除一些在另一个类似 table 中不可用的行。我可以使用这段代码 select 正确地删除要删除的行
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
时出现错误,因为我无法为第一个 table.
添加别名
Msg 156, Level 15, State 1, Line 2
Incorrect syntax near the keyword 'as'.
如何在不使用别名正确 select 行的情况下删除这些值?
将您的别名放在 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
)
好的,你可以像这样使用别名
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
AND
)
我需要从 table 中删除一些在另一个类似 table 中不可用的行。我可以使用这段代码 select 正确地删除要删除的行
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
时出现错误,因为我无法为第一个 table.
Msg 156, Level 15, State 1, Line 2
Incorrect syntax near the keyword 'as'.
如何在不使用别名正确 select 行的情况下删除这些值?
将您的别名放在 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
)
好的,你可以像这样使用别名
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
AND
)