檢視oracle資料庫所有表的主外來鍵的關係

2021-08-30 23:43:25 字數 1103 閱讀 3534

在日常資料維護中,經常刪除資料,要是這些資料所在的表有外來鍵關聯,又不設定成級聯刪除的話,就需要先清空子表的相關資料了。要找出所有的主外來鍵的關聯是乙個比較頭疼的事情,下面給出乙個例子,可以得到某使用者下的所有主外來鍵關係:

select

pk_table 主鍵表,

pk_col 主鍵表id,

fk_table 外來鍵表,

fk_col 外來鍵表id,

pk_con constraint_name,

del_rule dellete_rule

from

(select

a.constraint_name pk_con,

a.table_name pk_table,b.column_name pk_col,

a.owner pk_owner

from user_constraints a,user_cons_columns b

where (a.constraint_type='p' or a.constraint_type='u')

and a.constraint_name=b.constraint_name

and a.owner=b.owner) pk,

(select c.constraint_name fk_con,

c.table_name fk_table,

c.delete_rule del_rule,

d.column_name fk_col,

c.r_owner r_pk_owner,

c.r_constraint_name r_pk_con,

c.owner fk_owner

from user_constraints c,user_cons_columns d

where c.constraint_type='r'

and c.constraint_name=d.constraint_name

and c.owner=d.owner) fk

where pk.pk_owner=fk.r_pk_owner

and pk.pk_con=fk.r_pk_con

order by pk.pk_con for update

Oracle資料庫檢視所有表的常用系統表

獲取字段注釋 select from all col comments 獲取表字段 select from user tab columns where table name 使用者表 order by column name 獲取表注釋 select from user tab comments ...

如何檢視oracle資料庫中的所有表

覺得你應該先弄清楚oracle的常規資料字典的結構,像9i裡的常規資料字典中物件名稱就有以user,all,dba為字首的物件。以user為例,我們查該物件下有些什麼表,就應該執行下列的語句 sql select table name from user tables 類似的,你可以進行替換。如果你...

Oracle資料庫 查詢所有表

1.查詢當前資料庫下的所有表 select from all tables where owner test 注 all tables查出來是查得所有使用者下的表,當然也包括你登入的用下的表,然後加乙個where你要查的那個使用者名稱就可以了。記得使用者名稱要大寫 2.查詢當前資料庫下某個例項資料庫...