If 2 databases are on the same machine:
INSERT INTO database_a. Table1 (col1,col2,col3----)
Select col11,col22,col33--from Database_b. Table11
If not on the same machine, it is the content of this article:
-----------------------------------------------------------------------------------------
Query SQL statements across servers sample
INSERT into [target database name]. [dbo]. [Table name]
([target_id]
, [Target_name])
SELECT * FROM
OpenDataSource (' SQLOLEDB ', ' Data source= server; dbn= source database name; uid= user name; pwd= password '). source database name. dbo. [Table name]
But the above query needs to open the perimeter database query
First select the master database, create a new query, and execute the following SQL
External Account:
exec sp_configure ' show advanced options ', 1
Reconfigure
exec sp_configure ' Ad Hoc distributed Queries ', 1
Reconfigure
-------------------------------
Close the perimeter:
exec sp_configure ' show advanced options ', 0
Reconfigure
exec sp_configure ' Ad Hoc distributed Queries ', 0
Reconfigure
Query SQL statements across servers sample