取得MySQL数据库表,列信息的SQL语句 荣

/*取得表信息*/
select table_Comment as Script, table_Name as TableName, 0 as id, Create_Time as createDate,
CASE table_Type WHEN 'BASE TABLE' then 'U' when 'VIEW' then 'V' ELSE table_Type END as tableType,
0 as Category from tables;

/*取得外键关系*/
SELECT CONSTRAINT_Name as Script, CONSTRAINT_Name as TableName, 0 as id,
 CURRENT_TIMESTAMP  as createDate, 
       CASE CONSTRAINT_TYPE
      WHEN 'FOREIGN KEY' THEN 'F'
      WHEN 'PRIMARY KEY' THEN 'K'   
            ELSE CONSTRAINT_TYPE
     END AS tableType,  0 as Category  From TABLE_CONSTRAINTS;       

SELECT Table_Name, Column_Name, Column_Type, Column_Key, Column_Comment From Columns ;

/*取得列信息*/
select table_name as tablename, column_Name as columnName, column_type as columnType,
0 as columntypeindex, CHARACTER_OCTET_LENGTH as length, Numeric_Precision as decimaldigits, 
column_comment as Script,column_default as defaultvalue, is_nullable as isnullable,
case extra when  'auto_increment' then 1 else 0 end as IsMarking,
0 as colid, 'U' as ObjectType, data_type from columns;

原文地址:https://www.cnblogs.com/admin11/p/1688274.html