我正在使用SQL Server 2005中的一個數據庫,在所有我需要它們的表中沒有唯一標識。我的解決方法是創建另一組具有強制唯一ID的類似表。在一個表中設置字段等於另一個字段在某些條件下
我現在想要將新ID的引用返回到用於Join目的等等的初始表的集合。 (另外:這些表格會被截斷和重新填充,因此是解決方法)。
換句話說:我想在Table2中使用ID並正確地與Table1中的記錄相關聯。
對我而言,困難的一點是Table1中的記錄只有在考慮三個字段時纔是唯一的。
我在表1中添加一個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.
有什麼想法?
謝謝。
您好,感謝。我對t和table1,t2和table2之間的區別在速記中感到困惑? – user1893148 2013-02-23 21:37:18
@ user1893148 - np,這些只是表名的別名。希望這有助於! – sgeddes 2013-02-23 21:38:43
@ user1893148 - 與此相同:http://sqlfiddle.com/#!3/75c9c/1 - 只是更容易輸入:)祝你好運! – sgeddes 2013-02-23 21:40:14