简体   繁体   English

列出所有SQL实例及其表

[英]List all SQL instances, and their tables

I want to list all SQL server instances and their tables. 我想列出所有SQL Server实例及其表。

I have code that lists all the servers correctly but I cannot seem to get a list of their tables. 我有正确列出所有服务器的代码,但似乎无法获得其表的列表。

        DataTable dataSources = SqlDataSourceEnumerator.Instance.GetDataSources();
        foreach (DataRow row in dataSources.Rows)
        {
            Console.WriteLine("Server Name:" + row["ServerName"]);

            foreach (var item in row.ItemArray)
            {
                Console.WriteLine(" - Item: "+ item);
            }
        }

You can query what tables are in a db using sys.Tables . 您可以使用sys.Tables查询数据库中的sys.Tables See below: 见下文:

USE YourDBName
GO
SELECT name FROM sys.Tables
GO 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM