1. 程式人生 > >跨伺服器 快速 匯入資料表記錄 Insert into SELECT

跨伺服器 快速 匯入資料表記錄 Insert into SELECT

Use DataBaseName

/*開啟Ad Hoc Distributed Queries元件
 
exec sp_configure 'show advanced options',1
reconfigure
exec sp_configure 'Ad Hoc Distributed Queries',1
reconfigure

*/

 

Insert into tableName (col1,col2,col3,……) --欄位不能含有主鍵

SELECT  col1,col2,col3,……
     
from opendatasource
(
    'SQLOLEDB',
    'Data Source=192.168.0.1;User ID=dbuser;Password=123456'
).DataBaseName.dbo.tableName 
WHERE [datetime]>'2016-11-01 15:00:18.663' 
AND [datetime]<'2016-11-01 15:00:18.663'

/*關閉Ad Hoc Distributed Queries元件

exec sp_configure 'Ad Hoc Distributed Queries',0
reconfigure
exec sp_configure 'show advanced options',0
reconfigure
*/