以下代码适合MSSQL2005
if exists(select 1 from sysservers where srvname = '')
begin exec sp_dropserver '','droplogins' end EXEC sp_addlinkedserver @server='', @srvproduct='', @provider='SQLOLEDB', @datasrc=''Exec sp_serveroption '','rpc','TRUE' Exec sp_serveroption '','rpc out','TRUE' EXEC sp_addlinkedsrvlogin '', 'false', NULL, '',''EXEC sp_addlinkedsrvlogin '', 'false', 'sa','',''举例:
if exists(select 1 from sysservers where srvname = 'U8S')
begin exec sp_dropserver 'U8S','droplogins' end EXEC sp_addlinkedserver @server='U8S', @srvproduct='', @provider='SQLOLEDB', @datasrc='(local)' Exec sp_serveroption 'U8S','rpc','TRUE' Exec sp_serveroption 'U8S','rpc out','TRUE' EXEC sp_addlinkedsrvlogin 'U8S', 'false', NULL, 'sa','password' EXEC sp_addlinkedsrvlogin 'U8S', 'false', 'sa','sa','password'