我正在使用 SQL Server 2005 中的数据库,该数据库在我需要它们的所有表中都没有唯一 ID。我的解决方法是创建另一组具有强制唯一 ID 的类似表。
我现在想将新 ID 的引用带回到初始表集以用于连接等目的。(除此之外:这些表会被定期截断和重新填充,因此是解决方法)。
换句话说:我想在 Table2 中获取 ID,并与 Table1 中的记录正确关联。
对我来说困难的是 Table1 中的记录只有在考虑三个字段时才是唯一的。
我在 Table1 中添加了一个 ID 字段,然后我尝试了以下操作:
UPDATE dbo.Table1
SET dbo.Table1.ID = dbo.Table2.ID
WHERE dbo.Table1.foo = dbo.Table2.foo
And dbo.Table1.bar = dbo.Table2.bar
And dbo.Table1.buzz = dbo.Table2.buzz
但是,我收到以下错误:
Msg 4104, Level 16, State 1, Line 1
The multi-part identifier "dbo.Table2.foo" could not be bound.
Msg 4104, Level 16, State 1, Line 1
The multi-part identifier "dbo.Table2.bar" could not be bound.
Msg 4104, Level 16, State 1, Line 1
The multi-part identifier "dbo.Table2.buzz" could not be bound.
有什么想法吗?
谢谢。