Step 1:
First Create a Function for getting Object which is using linked server
CREATE FUNCTION [dbo].[fuGetLinkedServerNameInSPs](@ServerName varchar(MAX))
RETURNS @Return TABLE (XName varchar(200),XType Varchar(3))
AS
BEGIN
;WITH cteTableValueCollection(Name,Type)
AS
(
SELECT DISTINCT o.name, o.xtype FROM syscomments c
INNER JOIN sysobjects o ON c.id=o.id WHERE c.TEXT LIKE '%' + @ServerName + '%'
)
INSERT @Return SELECT Name,Type FROM cteTableValueCollection
RETURN
END
Step 2 :
Getting Linked server Names in DB.
create table #tmpLinkedServerNames(SeqID int Identity(1,1),SRV_Name varchar(100),SRV_ProviderName varchar(50),SRV_Product varchar(50),SRV_Datasource Varchar(50),
SRV_Providerstring varchar(50),SRV_Location varchar(50),SRV_Cat varchar(50))
insert into #tmpLinkedServerNames(SRV_Name,SRV_ProviderName,SRV_Product,SRV_Datasource,SRV_Providerstring,SRV_Location,SRV_Cat) exec sp_linkedservers
select * from #tmpLinkedServerNames
Getting Whole List
Declare @MaxCount tinyint,@NextCount tinyint,@LinkedServerName Varchar(50)
Declare @spList Table(LinkedServerName Varchar(20),objectName Varchar(50),ObjectType Varchar(3))
-- Get the Linked Server Count
select @MaxCount=MAX(seqid) from #tmpLinkedServerNames
set @NextCount = 1
while(@MaxCount >= @NextCount)
begin
-- One by one process
select @LinkedServerName = SRV_Name From #tmpLinkedServerNames where SeqID = @NextCount
insert into @spList(LinkedServerName,objectName,ObjectType) select @LinkedServerName,XName,XType from [dbo].[fuGetLinkedServerNameInSPs](@LinkedServerName)
Set @NextCount = @NextCount + 1
end
Now the Table display the Entire list that is having linked server name.
select * from @spList
First Create a Function for getting Object which is using linked server
CREATE FUNCTION [dbo].[fuGetLinkedServerNameInSPs](@ServerName varchar(MAX))
RETURNS @Return TABLE (XName varchar(200),XType Varchar(3))
AS
BEGIN
;WITH cteTableValueCollection(Name,Type)
AS
(
SELECT DISTINCT o.name, o.xtype FROM syscomments c
INNER JOIN sysobjects o ON c.id=o.id WHERE c.TEXT LIKE '%' + @ServerName + '%'
)
INSERT @Return SELECT Name,Type FROM cteTableValueCollection
RETURN
END
Step 2 :
Getting Linked server Names in DB.
create table #tmpLinkedServerNames(SeqID int Identity(1,1),SRV_Name varchar(100),SRV_ProviderName varchar(50),SRV_Product varchar(50),SRV_Datasource Varchar(50),
SRV_Providerstring varchar(50),SRV_Location varchar(50),SRV_Cat varchar(50))
insert into #tmpLinkedServerNames(SRV_Name,SRV_ProviderName,SRV_Product,SRV_Datasource,SRV_Providerstring,SRV_Location,SRV_Cat) exec sp_linkedservers
select * from #tmpLinkedServerNames
Getting Whole List
Declare @MaxCount tinyint,@NextCount tinyint,@LinkedServerName Varchar(50)
Declare @spList Table(LinkedServerName Varchar(20),objectName Varchar(50),ObjectType Varchar(3))
-- Get the Linked Server Count
select @MaxCount=MAX(seqid) from #tmpLinkedServerNames
set @NextCount = 1
while(@MaxCount >= @NextCount)
begin
-- One by one process
select @LinkedServerName = SRV_Name From #tmpLinkedServerNames where SeqID = @NextCount
insert into @spList(LinkedServerName,objectName,ObjectType) select @LinkedServerName,XName,XType from [dbo].[fuGetLinkedServerNameInSPs](@LinkedServerName)
Set @NextCount = @NextCount + 1
end
Now the Table display the Entire list that is having linked server name.
select * from @spList
03:42 |
Category:
SQL SERVER
|
0
comments
Comments (0)