![](/img/trans.png)
[英]`NOT NULL` constraints passed while creating new table from existing table?
[英]How to find constraints for existing table?
如何找到現有表的完整性約束(例如主鍵)? 我正在使用Oracle 10g。
查找表上的約束:
select constraint_name, constraint_type
from user_constraints
where table_name = 'YOUR_TABLE'
如果需要在其他模式中查找對表的約束,則有匹配的字典視圖ALL_和DBA_。
四種約束類型是
檢查約束包括我們不立即將其視為約束的內容,例如NOT NULL。
因此,要在表上查找主鍵...
select constraint_name, constraint_type
from user_constraints
where table_name = 'YOUR_TABLE'
and c.constraint_type = 'P'
要查找外鍵中引用的表:
select c.constraint_name as foreign_key
, c.r_constraint_name as referenced_constraint
, p.table_name
from user_constraints c
join user_constraints p
on p.constraint_name = c.r_constraint_name
where c.table_name = 'YOUR_TABLE'
and c.constraint_type = 'R'
/
您需要查詢數據字典,特別是USER_CONS_COLUMNS視圖,以查看表列和相應的約束:
SELECT * FROM user_cons_columns WHERE table_name = '<your table name in caps>';
如果您要查找有關數據模型的信息,請使用為該作業構建的工具。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.