如果数据库两边都没有密码可以写
exec sp_addlinkedserver [servername]
go
select * from [192.168.1.1].st_ccerp.dbo.lsdtxb
如果有密码的话就要写成:
exec sp_addlinkedserver [servername]
go
exec sp_addlinkedsrvlogin 'servername', 'false ',null, 'username', 'password'
go
或
EXEC sp_configure 'show advanced options', 1;
GO
RECONFIGURE;
GO
EXEC sp_configure 'Ad Hoc Distributed Queries', 1;
GO
RECONFIGURE;
GO
select * FROM OPENROWSET('SQLOLEDB','192.168.1.1';'sa';'softccerp4725205',
'SELECT * FROM st_ccerp.dbo.lsdtxb')