简体   繁体   中英

List all SQL instances, and their tables

I want to list all SQL server instances and their tables.

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 . See below:

USE YourDBName
GO
SELECT name FROM sys.Tables
GO 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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