Link Server Script

  • I have used to sp_helpserver to get me listing of the link servers on my server; is there there a way to get a listing of tables on the linkserver by the link server name?

  • How about

    select * from [linkedServer].[dbName].sysobjects where xtype = 'u'

  • I gave that a try but i received the following error invalid object name linksername.dbname.sysobjects

  • First off, is this a SQL Server linked server? If not, then sysobjects very well may not apply. If it is SQL Server, what version? If it's 2005 try this:

    select name

    from [LinkedServername].database.sys.objects

    where type='u'

    DAB

  • thanks for the reply; not all the servers are SQL servers. I have an informix, and MySQL server. What i am trying to do is create a user drop list of linked servers (which i can do). What i want is when the user selects one of the linked servers that i can populate another drop list containing the listing of tables on that linked server. At run time the only information i can attain is the basic information provided from SQL (sp_helpserver) which only provides the link server name.

  • I don't know anything about Infromix, but for MySQL you can execute the following:

    select * from openquery (MYSQL, ' select table_schema, table_name

    from information_schema.TABLES; ' )

    DAB

  • Thank you very much for the quick response.

    That provided the data that i wanted. I kicking myself for forgetting about using OPENQUERY to retrieve the information.

    I really appreciate the help,

    - Mike

  • Glad I could help. One more item. Beware if your MySQL instance is running on a *nix server. If that is the case you will need to take case into account as information_schema <> INFORMATION_SCHEMA, etc.

    DAB

  • More universal script:

    select *

    from master.dbo.SYSREMOTE_TABLES (

    'linked_server_name',

    NULL,

    NULL,

    NULL,

    NULL )

    Works not only on SQL Server remote servers but any kind of remote servers, including ODBC connection to files using Jet.OLEDB driver.

    _____________
    Code for TallyGenerator

  • Hi,

    is there an equivalent query for SQL 2005?

  • INFORMATION_SCHEMA is an ANSI standard, so it should work on most RDBMSes, although I've never tried it on other vendors' platforms. It certainly works on SQL 2000 and 2005.

    John

  • I think he's asking for a 2005 equivalent of master.dbo.SYSREMOTE_TABLES

  • Yes, i tried the query

    select *

    from master.dbo.SYSREMOTE_TABLES (

    'LnkServerName',

    NULL,

    NULL,

    NULL,

    NULL )

    and it works great on 2000 but on 2005 which we will be upgrading towards in the next few weeks it does not work.

    i appreciate the help everyone is providing...

  • Yes, I think you're right. However, that appears to be an undocumented table or view in SQL 2000 that didn't survive to 2005. That's the danger of using undocumented features.

    John

  • This solution should work for 2000 and 2005:

    sp_catalogs ' '

    DAB

Viewing 15 posts - 1 through 15 (of 16 total)

You must be logged in to reply to this topic. Login to reply