【发布时间】:2013-05-29 16:05:35
【问题描述】:
事情是这样的:我有 2 个数据库 ADatabaseCX 和 ADatabaseRH。数据库是一样的。我在两个数据表中都有一些记录。我想做的是将 ADatabaseCX 中的条目插入到 ADatabaseRH,但只有条目,在 ADatabaseRH 中不存在 - 在 RH 中有不完整的数据。
我尝试使用嵌套 SQL,如下所示:
SELECT a.*
FROM ADatabaseCX.dbo.Recipes AS a
LEFT JOIN ADatabaseRH.dbo.Recipes AS b ON (ADatabaseCX.dbo.Recipes.recipeId = ADatabaseRH.dbo.Recipes.recipeId)
WHERE b.recipeId IS NULL
但它说
Msg 4104, Level 16, State 1, Line 3
The multi-part identifier "ADatabaseCX.dbo.Recipes.recipeId" could not be bound.
Msg 4104, Level 16, State 1, Line 3
The multi-part identifier "ADatabaseRH.dbo.Recipes.recipeId" could not be bound.
拳头(第一个想法)我试过了
SELECT * FROM ADatabaseCX.dbo.Recipes
WHERE NOT EXISTS (SELECT recipeId FROM ADatabaseRH.dbo.Recipes)
但这没有返回任何记录。
在复制时,我还希望以保持 ID 不变的方式进行复制。
我使用的是 MS SQL Server 2008。 任何帮助将不胜感激。
【问题讨论】: