復制代碼 代碼如下:
truncate table TestTable
EXEC sp_configure 'show advanced options', 1; -- 開啟高級配置
RECONFIGURE
EXEC sp_configure 'Ad Hoc Distributed Queries', 1;--開啟分布式查詢
RECONFIGURE
set IDENTITY_insert TestTable on --設置 某表允許插入遞增量
INSERT INTO TestTable(ID,Date,Info )SELECT a.ID,a.Date,a.Info
FROM OPENROWSET('SQLOLEDB','V';'sa';'123456',
'SELECT * FROM TestDatabase.dbo.TestTable') AS a
set IDENTITY_insert TestTable OFF --設置 不某表允許插入遞增量
EXEC sp_configure 'Ad Hoc Distributed Queries', 0;--關閉分布式查詢
RECONFIGURE
EXEC sp_configure 'show advanced options', 0;--關閉高級配置
RECONFIGURE