做个笔记,仅供参考
SELECT d.TABLE_NAME tbName,//表名COALESCE(t.COMMENTS, ' ') tbDesc, //表注释a.COLUMN_NAME columnName, //字段名a.DATA_TYPE columnType, //字段类型a.DATA_LENGTH width, //字段长度a.DATA_SCALE precision,//字段小数位decode(a.NULLABLE,'Y','0','1') notNull,//是否允许空COALESCE(m.COMMENTS, ' ') comments, //字段备注decode(k.uniqueness,'UNIQUE','1','0') uniques, //是否唯一COALESCE(k.index_name, ' ') indexName,//如果是索引,索引名decode(k.key,'Y','1','0') masterKey//是否主键FROMuser_tab_columns aINNER JOIN user_tables d on a.TABLE_NAME=d.TABLE_NAMELEFT JOIN user_tab_comments t ON t.TABLE_NAME=d.TABLE_NAMELEFT JOIN user_col_comments m ON m.COLUMN_NAME=a.COLUMN_NAME AND m.TABLE_NAME=d.TABLE_NAMELEFT JOIN(SELECT e.index_name,u.TABLE_NAME,u.COLUMN_NAME,e.uniqueness,decode(p.constraint_name,NULL,'N','Y') keyfrom user_indexes e INNER JOIN user_ind_columns u ON e.index_name=u.index_nameLEFT JOIN ( select constraint_name from user_constraints where constraint_type='P' ) p ON e.index_name=p.constraint_name) k ON k.TABLE_NAME=a.TABLE_NAME and k.COLUMN_NAME=a.COLUMN_NAMEORDER BY tbName
备注:user_开头是当前用户,all_开头所有用户,dba_开头包括系统表
新闻热点
疑难解答