How to list all tables & columns names of a linked-server database in SQL Server?

前端 未结 4 1931
情书的邮戳
情书的邮戳 2021-01-13 02:20

If it\'s a regular database, i can simply use this query to get a list of all table names and their column names of the database.

use [my_database_name]
GO

         


        
4条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-13 02:53

    Fully qualify your linked server in your FROM and JOIN, and alias them.

    SELECT lst.name AS Table_Name, 
           lsc.name AS Column_Name, 
           lsc.max_length, 
           (schema_id) As Schema_name
    
    FROM [SERVER].[DB].[sys].[tables] lst
        INNER JOIN [SERVER].[DB].[sys].[columns] lsc
            ON lst.OBJECT_ID=lsc.object_id
    
    ORDER BY schema_name, lst.name, lsc.name
    

提交回复
热议问题