下面為您介紹的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表信息的語句寫法。
PHP中常用到的一些MySQL語句
教您在mysql查找效率慢的SQL語句
mysql UPDATE語句的使用方法
MySQL中INSERT的一般用法
MySQL索引類型介紹