Get table names from a database

后端 未结 7 1443
夕颜
夕颜 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:39
    SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE='BASE TABLE'
    
    0 讨论(0)
  • 2021-01-04 04:40

    In MySQL this will list all databases:

    show databases;
    

    For each of these you can do:

    use <database_name>;
    

    and then

    show tables;
    
    0 讨论(0)
  • 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<Table> 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<Table>().ToList();
            }
    
    0 讨论(0)
  • 2021-01-04 04:54

    In SQL SERVER, you can just use -

    select * from sys.tables
    
    0 讨论(0)
  • 2021-01-04 04:55

    I used this query:

    SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE='BASE TABLE'
    

    It gives me table name as well as sysDiagram(database diagram generated for that database)

    0 讨论(0)
  • 2021-01-04 04:58

    Here is the MySQL query you asked.

    SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='mp21'
    
    0 讨论(0)
提交回复
热议问题