との関係を持ってTABLE1と列の主キーを取得したいです。たとえば、
表DEPT
には主キーがあり、表EMP
にはDEPT
を指す外部キーがあります。最初に、DEPT
の主キーの制約名、次に列を見つけます。次に、制約名を手にして、外部キーの制約名と列を見つけます(EMP
)。
select table_name, constraint_name, constraint_type
from user_constraints
where table_name = 'DEPT'
and constraint_type = 'P'
;
TABLE_NAME CONSTRAINT_NAME CONSTRAINT_TYPE
---------- --------------- ---------------
DEPT PK_DEPT P
select constraint_name, table_name, column_name, position
from user_cons_columns
where constraint_name = 'PK_DEPT'
;
CONSTRAINT_NAME TABLE_NAME COLUMN_NAME POSITION
--------------- ---------- ----------- --------
PK_DEPT DEPT DEPTNO 1
、その後
select table_name, constraint_name, constraint_type
from user_constraints
where table_name = 'EMP'
and r_constraint_name = 'PK_DEPT'
;
TABLE_NAME CONSTRAINT_NAME CONSTRAINT_TYPE
---------- --------------- ---------------
EMP FK_DEPTNO R
select constraint_name, table_name, column_name, position
from user_cons_columns
where constraint_name = 'FK_DEPTNO'
;
CONSTRAINT_NAME TABLE_NAME COLUMN_NAME POSITION
--------------- ---------- ----------- --------
FK_DEPTNO EMP DEPTNO 1
これは、MySQLの質問は、Oracleの質問、またはSQL Serverの問題ですか?この3つのタグはすべてタグが付けられていますが、まったく別の商品で、この質問とはまったく異なる回答をしています。 – pmbAustin