查詢外來鍵約束、子表欄位等資訊的SQL
查詢關聯到一個父表的所有子表欄位
select owner,constraint_name,constraint_type,table_name,r_owner,r_constraint_name
from dba_constraints where r_constraint_name in (select constraint_name from dba_constraints where table_name='HEALTH_FEE')
order by owner,constraint_name;
select a.* from dba_cons_columns a,
(
select owner,constraint_name,constraint_type,table_name,r_owner,r_constraint_name
from dba_constraints where r_constraint_name in (select constraint_name from dba_constraints where table_name='STAFF_INFO')) b
where a.table_name=b.table_name
and a.constraint_name=b.constraint_name
and a.column_name like '%FCU%'
order by a.owner,a.table_name,a.constraint_name;
---查詢存在外來鍵的欄位列
select a.owner,a.table_name,a.constraint_name,a.column_name from dba_cons_columns a,
(
select owner,constraint_name,constraint_type,table_name,r_owner,r_constraint_name
from dba_constraints where r_constraint_name in (select constraint_name from dba_constraints where table_name in ('BANK_TBL'))
) b
where a.table_name=b.table_name
and a.constraint_name=b.constraint_name
order by a.owner,a.table_name,a.constraint_name;
---查詢存在外來鍵的表和約束名
select a.owner,a.constraint_name,a.table_name,
a.r_owner,a.r_constraint_name from dba_constraints a where a.constraint_type='R' and wner='NETS2DATA'
and exists (select constraint_name
from dba_constraints b where b.owner='NETS2DATA' and a.r_constraint_name=b.constraint_name
and (b.constraint_type='P' or
b.constraint_type='U'));
---查詢存在外來鍵的欄位列
select a.owner,a.table_name,a.constraint_name,a.column_name from dba_cons_columns a,
(
select a.owner,a.constraint_name,a.table_name,
a.r_owner,a.r_constraint_name from dba_constraints a where a.constraint_type='R' and wner='NETS2DATA'
and exists (select constraint_name
from dba_constraints b where b.owner='NETS2DATA' and a.r_constraint_name=b.constraint_name
and (b.constraint_type='P' or
b.constraint_type='U'))
) b
where a.owner=b.owner
and a.table_name=b.table_name
and a.constraint_name=b.constraint_name
order by a.owner,a.table_name,a.constraint_name;
---查詢沒有建立外來鍵索引的欄位資訊
select * from (select a.owner,a.table_name,a.constraint_name,a.column_name from dba_cons_columns a,
(
select a.owner,a.constraint_name,a.table_name,
a.r_owner,a.r_constraint_name from dba_constraints a where a.constraint_type='R' and wner='NETS2DATA'
and exists (select constraint_name
from dba_constraints b where b.owner='NETS2DATA' and a.r_constraint_name=b.constraint_name
and (b.constraint_type='P' or
b.constraint_type='U'))
) b
where a.owner=b.owner
and a.table_name=b.table_name
and a.constraint_name=b.constraint_name ) tbl
where not exists(select 'X' from dba_ind_columns idx
where tbl.owner=idx.table_owner
and tbl.table_name=idx.table_name
and tbl.column_name=idx.column_name
and idx.column_position=1);
類別:dba指令碼 檢視評論Link URL: http://hi.baidu.com/ljm0211/blog/item/2d03a0443a577c99b3b7dc39.html
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/11411056/viewspace-732755/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 查詢oracle表的資訊(表,欄位,約束,索引)Oracle索引
- 關於外來鍵約束和對應主鍵資訊的查詢指令碼指令碼
- SQL的主鍵和外來鍵約束SQL
- oracle查詢表資訊(索引,外來鍵,列等)Oracle索引
- sql: 查詢約束SQL
- Javaweb-約束-外來鍵約束JavaWeb
- SQL外來鍵約束的含義及建立SQL
- Oracle定義約束 外來鍵約束Oracle
- 查詢(看)表的主鍵、外來鍵、唯一性約束和索引索引
- Oracle 外來鍵查詢sqlOracleSQL
- SQL SERVER中找出拙劣的約束,索引,外來鍵SQLServer索引
- ORACLE: 查詢(看)表的主鍵、外來鍵、唯一性約束和索引Oracle索引
- oracle外來鍵約束的總結Oracle
- MySQL查詢索引的選擇性、索引欄位、註釋等基本資訊的SQLMySql索引
- MySQL 查詢索引的選擇性、索引欄位、註釋等基本資訊的SQLMySql索引
- MySQL 欄位約束MySql
- SQL“多欄位模糊匹配關鍵字查詢”SQL
- 修改oracle的約束欄位Oracle
- 教你mysql如何增加外來鍵約束MySql
- MySQL禁用恢復外來鍵約束MySql
- 【MySQL】MySQL進階(外來鍵約束、多表查詢、檢視、備份與恢復)MySql
- Oracle外來鍵約束中NULL的處理OracleNull
- Oracle 查詢欄位詳細資訊Oracle
- mysql 刪除老是報外來鍵約束MySql
- 【實驗】【外來鍵】小議外來鍵約束對應用程式的影響
- 查詢emp表上的所有約束的詳細資訊
- (轉)oracle資料庫中所有外來鍵約束失效SQL語句Oracle資料庫SQL
- AppBoxFuture(七): 分散式外來鍵約束APP分散式
- mysql不能新增外來鍵約束怎麼辦MySql
- mysql啟動和關閉外來鍵約束MySql
- 詳解外來鍵約束(foreign key)
- 5_MySQL 表的欄位約束MySql
- SQL SERVER 資料庫查詢表和欄位資訊語句SQLServer資料庫
- 資料完整性約束:主鍵、外來鍵、各種約束的建立刪除語句
- Django模型之欄位與約束Django模型
- 遷移後處理外來鍵約束的問題
- 查詢沒有索引的外來鍵索引
- 查詢一個表的外來鍵