2014-09-06

TSQL - Add self-referencing linked server (windows authentication)

exec sp_addlinkedserver
       @server='me'               -- here you can specify the name of the linked server
       , @srvproduct=''    
       , @provider='sqlncli'      -- using SQL Server native client
       , @datasrc='(local)' -- add here your server name
       , @location=''
       , @provstr=''
       , @catalog='THESIS'
;





-- Using MSDASQL... not optimal.
exec sp_addlinkedserver
       @server = 'me'
       , @srvproduct=''
       , @provider='MSDASQL'
       , @provstr='DRIVER={SQL Server}; Server=(local); Initial Catalog=master; Integrated Security=SSPI;'
;



Use this command instead, if using SQLEXPRESS...

exec sp_addlinkedserver
       @server = 'selfSQLEXPRESS'
       , @srvproduct=''
       , @provider='MSDASQL'
       , @datasrc=NULL
       , @location=NULL
       , @provstr='DRIVER={SQL Server}; Server=(local)\SQLEXPRESS; Initial Catalog=master; Integrated Security=SSPI;'
;


No comments:

Post a Comment