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

前端 未结 4 1969
情书的邮戳
情书的邮戳 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 03:11

    There is the solution to list:

    declare @temp table
    (
        col1 varchar(255),
        col2 varchar(255),
        [name] varchar(255),
        [type] varchar(255),
        col3 varchar(255)
    )
    insert @temp exec sp_tables_ex 'Your_LinkedServer_Name'
    select * from @temp
    

    And also open a cursor:

    DECLARE lstTables CURSOR FOR 
            select [name] from @temp
    

提交回复
热议问题