How to copy value from database1.table1.column1 to database2.table1.column1 in SQL Server?

Viewed 37

I have 2 similar databases with the same structure and different values in SQL Server.

I want to copy the values of one column of the table from the first database to the second database in the same table and column

database1.table1.column1 = database2.table1.column1

Thank you

2 Answers

Here's an example query to perform an update:

UPDATE t2
SET t2.column1 = t1.column1
FROM database1.table1 t1
INNER JOIN database2.table1 t2 ON t1.Id = t2.Id
INSERT INTO db2.schema2.table2 (col2)
    SELECT col1
    FROM db1.schema1.table1
GO

Where:

  • col1: the column you want to copy
  • col2: the column you want to insert the copied data into

But, before that, you will need to create the col2 and they should be the same data type.

Related