Situatie
Mai jos este o procedura ce returneaza toate obiectele care sunt apelate printr-un linked server ce este definit ca parametru in procedura.
Solutie
— exec ObiecteApelatePrinLinkedServer ‘Nume’
create proc ObiecteApelatePrinLinkedServer @LinkedServerName varchar(800)
as
declare @loopcount bigint,
@HoldServ varchar(800),
@linkcount int
create table #holdlinked
(
tabid bigint identity(1,1),
LinkedServerName varchar(800)
)
create table #holdinfo
(
tabid bigint identity(1,1),
LinkedServerName varchar(800),
ObjectName varchar(800),
ObjectType varchar(200)
)
if isnull(@LinkedServerName,’0′) = ‘0’
begin
insert into #holdlinked(LinkedServerName)
select name
From sys.servers
Where is_linked = 1
end
else
begin
insert into #holdlinked(LinkedServerName)
select name
From sys.servers
Where [name] = @LinkedServerName and is_linked = 1
end
select @linkcount = count(1)
from #holdlinked
set @loopcount = 1
while @loopcount <= @linkcount
begin
select @HoldServ = LinkedServerName
from #holdlinked
where tabid = @loopcount
insert into #holdinfo(LinkedServerName,ObjectName,ObjectType)
SELECT @HoldServ,OBJECT_NAME(sm.object_id),so.[type_desc]
FROM sys.sql_modules sm inner join sys.objects so on sm.object_id = so.object_id
WHERE Definition LIKE ‘%’+@HoldServ +’%’ AND (OBJECTPROPERTY(sm.object_id, ‘IsProcedure’) = 1 or
OBJECTPROPERTY(sm.object_id, ‘IsScalarFunction’) = 1 or
OBJECTPROPERTY(sm.object_id, ‘IsTable’) = 1 or
OBJECTPROPERTY(sm.object_id, ‘IsTableFunction’) = 1 or
OBJECTPROPERTY(sm.object_id, ‘IsView’) = 1 or
OBJECTPROPERTY(sm.object_id, ‘IsUserTable’) = 1 )
set @HoldServ = null
set @loopcount = @loopcount + 1
end
select LinkedServerName,ObjectType,ObjectName
from #holdinfo
order by LinkedServerName,ObjectName
Leave A Comment?