Get table names from a database

后端 未结 7 1556
夕颜
夕颜 2021-01-04 04:18

I\'ve searched through a bunch of websites and I have not come across any code or tutorial which has gone through the specifics of obtaining the table names from a single da

7条回答
  •  长情又很酷
    2021-01-04 04:53

    if you are asking about .net code then You need SMO :

    using Microsoft.SqlServer.Management.Smo;
    using Microsoft.SqlServer.Management.Common;
    
    
    
    public static List GetTables(string connection, string databaseName)
            {
                if (String.IsNullOrEmpty(connection))
                    throw new ArgumentException("connection is null or empty.", "connection");
    
                Server srv = getServer(connection);
                return srv.Databases[databaseName].Tables.Cast
    ().ToList(); }

    提交回复
    热议问题