Oracle中查询表字段基本信息、主键、外键

一,查询表基本信息

select
utc.column_name,utc.data_type,utc.data_length,utc.data_precision,
utc.data_Scale,utc.nullable,utc.data_default,ucc.comments
from
user_tab_columns utc,user_col_comments ucc
where
utc.table_name = ucc.table_name
and utc.column_name = ucc.column_name
and utc.table_name = 'ONLINEXLS'
order by
column_id

注意:order by column_id的意义是使得结果按照设计数据结构时的顺序显示。

二,查询表主键

select
col.column_name
from
user_constraints con,user_cons_columns col
where
con.constraint_name=col.constraint_name and con.constraint_type='P'
and col.table_name='ONLINEXLS'
三,查询表外键

select
distinct(ucc.column_name) column_name,rela.table_name,rela.column_name column_name1
from
user_constraints uc,user_cons_columns ucc,
(select t2.table_name,t2.column_name,t1.r_constraint_name from user_constraints t1,user_cons_columns t2 where t1.r_constraint_name=t2.constraint_name and t1.table_name='ONLINEXLS') rela
where
uc.constraint_name=ucc.constraint_name
and uc.r_constraint_name=rela.r_constraint_name
and uc.table_name='ONLINEXLS'

你可能感兴趣的:(oracle)