The value of the copy column from one .table database to another .table database

Let it be short and sweet

I want to do this (I failed many times, and one attempt even updated the line with spaces):

UPDATE Database2.Table1 SET (Database2.Table1.Column1, Database2.Table1.Column2, Database2.Table1.Column3) VALUES (Database1.Table1.Column1, Database1.Table1.Column2, Database1.Table1.Column3) WHERE Database2.Table1.Column1 = Database1.Table1.Column1 

These two already contain the same value, but the other 2 columns do not, and this is exactly what I want to change with this query.

This is what the table looks like:

Database1.Table1

 [id] [name] [applicationdate] [startdate] [shortdescription] [longdescription] [displayimg] [contact] [website] [created] [urlbase] [site] [keywords] [type] [location] 

Database2.Table1

 [id] [name] [applicationdate] [startdate] [content] [keywords] [customerid] [urlbase] [shortdescription] [meta] [type] [site] [searchurlbase] [lang] [educationlength] [locations] [educationwebsite] [contact] [tags] [educationtypes] [created] [category] 

Any help is greatly appreciated, thanks for your time :)

Sorry if this makes no sense, I am easily embarrassed when trying to explain the problems I am facing

+6
source share
2 answers
 UPDATE dest SET column2 = src.column2, column3 = src.column3 FROM Database2.dbo.Table1 AS dest INNER JOIN Database1.dbo.Table1 AS src ON dest.column1 = src.column1; 

Given your sorting problem, you can specify collate in the equality operation. Having no idea which side is causing the problem, and assuming you are not interested in case sensitivity:

 UPDATE dest SET column2 = src.column2, column3 = src.column3 FROM Database2.dbo.Table1 AS dest INNER JOIN Database1.dbo.Table1 AS src ON dest.column1 COLLATE Finnish_Swedish_CI_AS = src.column1 COLLATE Finnish_Swedish_CI_AS; 

If you need case sensitivity, change both sentences to _CS_AS_ .

+16
source

It is too easy in mysql if your databases are on the same server. Mysql command: insert into db2.table_name (column_name you want), select from table1_name.coumn_name from table 1

For example, insert in db2.new (id, name, email) select from register.id, register.name, register.email from register.

Where, db2 - 2nd db new - the table in db2 register is in db1, where you copy data from this db to db

-1
source

All Articles