Search code examples
sqlsql-serversql-updatedata-transfer

Copying data from one column to another table in a separate database on the same server


I am trying to figure out how to copy the data in one column back over to another table on the same server but in a separate database.

This will be done after performing an Entity Framework migration. I have tested it pretty thoroughly and know it will update the database schema correctly, but because of various reasons there is a column that will lose all of its data.

I have the original database (pre-EF migration) backed up and have created a duplicate database on the same server that I have restored that .bak file to.

What I am now trying to do is copy all of the data from the column in the backed up table (that gets cleared in the migration) back over to the post-migration table.

Here is the query I have so far:

UPDATE [PostMigDB].dbo.Issues 
SET Branch = [PreMigDB].dbo.IssueBranches.Branch
WHERE [PostMigDB].dbo.Issues.Id = [PreMigDB].dbo.IssueBranches.IssueId

But in the Query Editor, both expressions starting with [PreMigDB] are underlined in red and when I hover my mouse over them it reads:

The multi-part identifier [PreMigDB].dbo... could not be bound

Almost everything I have read online says this should be possible, but I cannot figure out why it won't work for me. Thank you all.


Solution

  • Try changing your join logic.

    UPDATE i
    SET Branch = b.Branch
    FROM [PostMigDB].dbo.Issues i
    INNER JOIN [PreMigDB].dbo.IssueBranches b ON b.IssueId = i.Id