mysql get table column names in alphabetical order

后端 未结 3 678
情深已故
情深已故 2020-12-09 03:22

Is it possible to query a MySQL database to get the column names of a table in alphabetical order? I know that

SHOW COLUMNS `table_name`;

3条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-09 03:54

    If you want more details, below query is really handy:

       SELECT COLUMN_NAME  as 'Field',
       COLUMN_TYPE    as 'Type',
       IS_NULLABLE    as 'Null',
       COLUMN_KEY     as 'Key',
       COLUMN_DEFAULT as 'Default',
       EXTRA          as 'Extra'
       from INFORMATION_SCHEMA.COLUMNS
       where TABLE_NAME   = 'my table' and
       TABLE_SCHEMA = 'my database'
       add ordering
       order by Type;  -- 
    

提交回复
热议问题