下面为您介绍的SQL语句可以取得MySQL表信息、外键关系等重要信息,有着很好的使用价值,如果您在MySQL表信息方面遇到过类似的问题,不妨一看。
/*取得表信息*/ 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;
以上就是取得MySQL表信息的语句写法。