逆水行船

别人的天堂,是我的异乡;无端的繁华,倍添我的惆怅

 

取得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;

posted on 2010-03-17 16:50  荣-  阅读(1166)  评论(0编辑  收藏  举报

导航