Solved

sql linked servers

Posted on 2010-08-26
2
317 Views
Last Modified: 2012-05-10
I have a sqlserver that contains six Linked Servers in its Server Objects.

I would like a stored procedure that would loop through all of the Linked Servers, listing their names, their Catalogs within each Linked Server and theirTables and Views.

0
Comment
Question by:LennyGray
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 16

Accepted Solution

by:
vdr1620 earned 250 total points
ID: 33535042
this will help you move further

http://support.microsoft.com/kb/203638
0
 
LVL 10

Assisted Solution

by:Marcjev
Marcjev earned 250 total points
ID: 33535147
use master
select * from sys.servers where is_linked = 1

This will give you a list of all linked servers. Use this data to construct a dynamic statement per server querying for all databases or catalogs.
Use a statement like select name from [founddbname].master.sys.databases to get this list.

This information you will need to create new dynamic statement of the kind 'select * from [servername].[databasename].sys.colums

Below is level one of this query you need.
use master
declare @statement varchar(500)
declare @name varchar(50)
declare curs cursor for select data_source from sys.servers where is_Linked = 1
open curs
fetch next from curs into @name
while @@fetch_status = 0
begin
   set @statement = 'SELECT * from [' + @name +'].master.sys.databases '
   EXEC(@statement)
end

Open in new window

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: When running hybrid database environments, you often need to query some data from a remote db of any type, while being connected to your MS SQL Server database. Problems start when you try to combine that with some "user input" pass…
In SQL Server, when rows are selected from a table, does it retrieve data in the order in which it is inserted?  Many believe this is the case. Let us try to examine for ourselves with an example. To get started, use the following script, wh…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

735 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question