Oracle中查詢表欄位基本資料、主鍵、外鍵

來源:互聯網
上載者:User

一,查詢表基本資料

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'

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.