SQL> desc s1;
Name Null? Type
------------------------- --------------------------------------------
ID NOT NULL NUMBER(4)
STUDENTID VARCHAR2(12)
STUDENTNAME VARCHAR2(8)
CLASSID NUMBER(4)
SQL> desc s2;
Name Null? Type
---------------- -------- --------------------------------------------
ID NOT NULL NUMBER(4)
CLASSNAME VARCHAR2(8)
SQL> select * from user_constraints c where c.constraint_type='R' and c.table_name='s1';
no rows selected
SQL> spool off我建了两个表s1和s2,s1中id为主键,classid为外键,s2中id为主键,为什么我查找s1外键信息是空的。
Name Null? Type
------------------------- --------------------------------------------
ID NOT NULL NUMBER(4)
STUDENTID VARCHAR2(12)
STUDENTNAME VARCHAR2(8)
CLASSID NUMBER(4)
SQL> desc s2;
Name Null? Type
---------------- -------- --------------------------------------------
ID NOT NULL NUMBER(4)
CLASSNAME VARCHAR2(8)
SQL> select * from user_constraints c where c.constraint_type='R' and c.table_name='s1';
no rows selected
SQL> spool off我建了两个表s1和s2,s1中id为主键,classid为外键,s2中id为主键,为什么我查找s1外键信息是空的。
from user_constraints a, user_constraints b
where a.constraint_type = 'R'
and b.constraint_type = 'P'
and a.r_constraint_name = b.constraint_name P 代表主键
R 代表外键 通过关联,能查询到你所想要的一切。