oracle 查询表的先关的信息

转载  贺同学

select 'carclaim(车险理赔)' as sysname,
       t.TABLE_NAME,
       c.comments,
       col.COLUMN_NAME,
       col.DATA_TYPE,
       col.DATA_LENGTH,
       comm.comments,
       col.NULLABLE,
       case uc.constraint_type
         when 'P' then
          'Y'
         else
          'N'
       end "primarkKey"
  from user_tables t -- 查询所有使用的表
 inner join user_tab_comments c --  表的注释 
on t.TABLE_NAME = c.table_name
 inner join user_tab_columns col -- 所有表的所有的字段的结构信息
on col.TABLE_NAME = t.TABLE_NAME
 inner join user_col_comments comm -- 所有表的所有的字段
on comm.table_name = col.TABLE_NAME
and comm.column_name = col.COLUMN_NAME
  left join (select ucc.table_name, ucc.column_name, uc.constraint_type
               from user_cons_columns ucc
              inner join user_constraints 
               -- user_constraints是表约束的视图,描述的是约束类型(constraint_type)是什么,属于哪些表(table_name),如果约束的类型为R(外键)的话,那么r_constraint_name字段存放的就是被引用主表中的主键约束名。   
               -- user_cons_columns是表约束字段的视图,说明表中的和约束相关的列参与了哪些约束。这些约束有主键约束,外键约束,索引约束.
               -- 两者可以通过(owner,constraint_name,table_name)关联
               uc on ucc.constraint_name =uc.constraint_name
              where uc.constraint_type = 'P'
                and ucc.table_name = 'GCADJUSTMENTMAIN') uc on uc.table_name =
                                                               col.TABLE_NAME
                                                           and uc.column_name =
                                                               col.COLUMN_NAME
 where t.TABLE_NAME in ('GCADJUSTMENTMAIN')
 ORDER BY col.TABLE_NAME, col.COLUMN_ID, UC.constraint_type;

发布了316 篇原创文章 · 获赞 33 · 访问量 21万+

猜你喜欢

转载自blog.csdn.net/yz18931904/article/details/105204856
今日推荐