MySQL Show Datadictionary of tables

前端 未结 6 1304
悲&欢浪女
悲&欢浪女 2021-01-13 09:40

I\'d like to show DataDictionary for entire tables in database.

SHOW COLUMNS
FROM `MyDataBase`.`MyTables` 
WHERE IN ( SELECT TABLE_NAME 
           FROM info         


        
6条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-13 10:22

    Here is what I use to generate a data dictionary when I have to:

    SELECT t.table_schema AS db_name,
           t.table_name,
           (CASE WHEN t.table_type = 'BASE TABLE' THEN 'table'
                 WHEN t.table_type = 'VIEW' THEN 'view'
                 ELSE t.table_type
            END) AS table_type,
            c.column_name,
            c.column_type,
            c.column_default,
            c.column_key,
            c.is_nullable,
            c.extra,
            c.column_comment
    FROM information_schema.tables AS t
    INNER JOIN information_schema.columns AS c
    ON t.table_name = c.table_name
    AND t.table_schema = c.table_schema
    WHERE t.table_type IN ('base table', 'view')
    AND t.table_schema LIKE '%'
    ORDER BY t.table_schema,
             t.table_name,
             c.ordinal_position
    

    This will list all of the databases on the server. You may want to change the where clause to only look at the specific table schema you want.

提交回复
热议问题