April 27, 2012

sp_helplinkedsrvlogin (Transact-SQL MetaData) Definition

Please note: that the following source code is provided and copyrighted by Microsoft and is for educational purpose only.
The meta data is from an SQL 2012 Server.

I have posted alot more, find the whole list here.

Goto Definition or MetaData

Definition:

sys.sp_helplinkedsrvlogin(nvarchar @rmtsrvname
, nvarchar @locallogin)

MetaData:

 create procedure sys.sp_helplinkedsrvlogin  
@rmtsrvname sysname = NULL,
@locallogin sysname = NULL
as
declare @srvid int,
@lgnid int

-- CHECK REMOTE SERVER NAME.
if @rmtsrvname is not null
begin
select @srvid = server_id from sys.servers where name = @rmtsrvname
if @srvid is null
begin
raiserror(15015,-1,-1,@rmtsrvname)
return (1)
end
end

-- IF SPECIFIED CHECK LOCAL USER NAME
if (@locallogin IS NOT NULL)
begin
select @lgnid = principal_id from sys.server_principals where name = @locallogin
end

select u.name as [Linked Server], t.name as [Local Login],
s.uses_self_credential as [Is Self Mapping], s.remote_name as [Remote Login]
from sys.linked_logins s left join sys.server_principals t
on s.local_principal_id=t.principal_id, sys.servers u
where ((@srvid is null or @srvid=u.server_id) and u.server_id= s.server_id)
and (@locallogin is null or @lgnid=s.local_principal_id)
order by u.name

-- RETURN SUCCESS
return(0) -- sp_helplinkedsrvlogin

No comments:

Post a Comment

Total Pageviews