這可能嗎?如果是的話,涉及到哪些表格,在哪個地方進行研究。查看所有對錶中某個列有外鍵的表?
6
A
回答
6
嘗試是這樣的
select uc.table_name
from sys.user_cons_columns ucc
join sys.user_constraints uc
on uc.r_constraint_name = ucc.constraint_name
where constraint_type = 'R'
and ucc.table_name = :1
and ucc.column_name = :2
其中
:1 = referenced table
:2 = referenced column
2
select * from user_constraints where r_constraint_name =<PK_NAME>
其中<PK_NAME>
是列的主鍵約束的名稱
2
有兩個候選查詢,這可能有助於在這裏:
http://www.alberton.info/oracle_meta_info.html
SELECT alc.constraint_name,
CASE alc.constraint_type
WHEN 'P' THEN 'PRIMARY KEY'
WHEN 'R' THEN 'FOREIGN KEY'
WHEN 'U' THEN 'UNIQUE'
WHEN 'C' THEN 'CHECK'
END "constraint_type",
alc.DELETE_RULE "on_delete",
CASE alc.deferrable WHEN 'NOT DEFERRABLE' THEN 0 ELSE 1 END "deferrable",
CASE alc.deferred WHEN 'IMMEDIATE' THEN 1 ELSE 0 END "initially_deferred",
alc.search_condition,
alc.table_name,
cols.column_name,
cols.position,
r_alc.table_name "references_table",
r_cols.column_name "references_field",
r_cols.position "references_field_position"
FROM all_cons_columns cols
LEFT JOIN all_constraints alc
ON alc.constraint_name = cols.constraint_name
AND alc.owner = cols.owner
LEFT JOIN all_constraints r_alc
ON alc.r_constraint_name = r_alc.constraint_name
AND alc.r_owner = r_alc.owner
LEFT JOIN all_cons_columns r_cols
ON r_alc.constraint_name = r_cols.constraint_name
AND r_alc.owner = r_cols.owner
AND cols.position = r_cols.position
WHERE alc.constraint_name = cols.constraint_name
AND alc.constraint_name = 'TESTCONSTRAINTS_ID_FK'
AND alc.table_name = 'TESTCONSTRAINTS2';
相關問題
- 1. 查找所有具有外鍵的表
- 2. 查看Oracle中表中的所有列
- 3. 如何查看以字母A開頭的所有表中的所有列(所有表中的列名相同)?
- 4. 查看所有表格中所有表格中的所有條目/數據
- 5. 獲取所有從屬表的所有外鍵的一個表到第n級
- 6. 查詢Django對象列表的外鍵
- 7. 如何查找表A的主鍵具有外鍵約束的表的列表?
- 8. 導出數據庫中的所有對象(表,主/外鍵,等..)
- 9. SQLite列表數據庫中的所有外鍵
- 10. 有沒有辦法檢查列表中的某個模式?
- 11. 編輯列表中有外鍵模型
- 12. 列出某個類的所有對象
- 13. SQL當外鍵2出現在第二個表中時,查找具有外鍵1的所有行
- 14. 在列表中查看兩列主鍵
- 15. MySQL:獲取某個數據庫中的表中的所有列
- 16. Django的 - 獲得一個表中的所有對象不具有外鍵的另一個表
- 17. 在python的字典列表中獲取某個鍵的所有值
- 18. MySQL刪除所有表,忽略外鍵
- 19. SQL Server:查看保留表的外鍵?
- 20. 如何查看某個值的所有有效位?
- 21. 更新列中的所有表中的行從另一個表的使用主鍵和外鍵
- 22. 檢查所有表列中的值
- 23. 從查找關鍵字列表中的所有句子與dict
- 24. 列表中所有Realm對象的ChangeListener
- 25. 列表中的所有用戶對象
- 26. Oracle - 在多個表中有外鍵
- 27. 所有LINQ查詢表達式關鍵字列表?
- 28. Linq查詢使所有調用帶來外鍵的表數據
- 29. 選擇兩個表中的所有行沒有一個外鍵屬性
- 30. sybase所有表中的所有varchar列