0

I need to update a single column from a backup version of a database. I've restored the backup to a different db location and am running the following:

update table_name
   Set
   column = restoredDB.dbo.table_name.column
From restoredDB.dbo.table_name
Where restoredDB.dbo.table.ID = table_name.ID

The following result is returned:

The multi-part identifier "table_name.ID" could not be bound

The ID field is a primary key, bigint. I've found many postings on the topic of "multi-part identifier could not be bound" however they don't seem to apply to my situation. Could someone explain why this is happening and how to correct the error?

Thx.

Jeremy
  • 121
  • 1
  • 2
  • 12

4 Answers4

2

All you need for column refernces is the TableName.ColumnName:

update table_name
   Set
   column = table_name.column
From restoredDB.dbo.table_name
Where table.ID = table_name.ID

Also, in your Where table.id = expression, you do not have any table name table in your example query.

RBarryYoung
  • 55,398
  • 14
  • 96
  • 137
0

You have to join the tables. To this:

from restoredDB.dbo.table_name

add this

join table_name on restoredDB.dbo.table.ID = table_name.ID

which means that you can get rid of this:

where restoredDB.dbo.table.ID = table_name.ID
Dan Bracuk
  • 20,699
  • 4
  • 26
  • 43
0

This should work:

UPDATE table_name SET table_name.column = restoredDB.dbo.table_name.column FROM table_name JOIN restoredDB.dbo.table_name.column ON table_name.ID = table_name.ID

Based on SQL update query using joins

Community
  • 1
  • 1
0

I think this should resolve the issue.

USE [<table_name_DB_Name>]
GO
UPDATE table_name
SET
column = t1.column
From restoredDB.dbo.table_name t1, table_name t2
Where t1.ID = t2.ID
Suman
  • 1