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 ' Show advanced Options ',1reconfigureexec'Ad Hoc distributed Queries', 1 Reconfigure
-------------------------------
Close the perimeter:
exec ' Show advanced Options ',0reconfigureexec'Ad Hoc distributed Queries', 0 Reconfigure
Query SQL statements across Servers sample (GO)