做个笔记,仅供参考
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//是否主键 from user_tab_columns a inner join user_tables d on a.table_name=d.table_name left join user_tab_comments t on t.table_name=d.table_name left join user_col_comments m on m.column_name=a.column_name and m.table_name=d.table_name left join ( select e.index_name,u.table_name,u.column_name,e.uniqueness,decode(p.constraint_name,null,'n','y') key from user_indexes e inner join user_ind_columns u on e.index_name=u.index_name left 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_name order by tbname
备注:user_开头是当前用户,all_开头所有用户,dba_开头包括系统表