SQL 分布式查询、插入递增列示例
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
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
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