特定のテーブル 'foo' に対して、foo を指す外部キーを持つ一連のテーブルを生成するためのクエリが必要です。Oracle 10G を使用しています。
61842 次
10 に答える
43
これは機能するはずです(または何か近いもの):
select table_name
from all_constraints
where constraint_type='R'
and r_constraint_name in
(select constraint_name
from all_constraints
where constraint_type in ('P','U')
and table_name='<your table here>');
于 2008-09-17T18:21:55.323 に答える
5
次のステートメントは、子とそのすべての子孫を与える必要があります。Oracle 10 データベースでテストしました。
SELECT level, main.table_name parent,
link.table_name child
FROM user_constraints main, user_constraints link
WHERE main.constraint_type IN ('P', 'U')
AND link.r_constraint_name = main.constraint_name
START WITH main.table_name LIKE UPPER('&&table_name')
CONNECT BY main.table_name = PRIOR link.table_name
ORDER BY level, main.table_name, link.table_name
于 2008-09-18T10:12:31.903 に答える
4
Mike のクエリをさらに一歩進めて、制約名から列名を取得する方法を次に示します。
select * from user_cons_columns
where constraint_name in (
select constraint_name
from all_constraints
where constraint_type='R'
and r_constraint_name in
(select constraint_name
from all_constraints
where constraint_type in ('P','U')
and table_name='<your table name here>'));
于 2014-05-28T15:14:46.750 に答える
1
Oracle Databaseオンライン・ドキュメントへのリンク
データ ディクショナリ ビューを参照することをお勧めします。それらには次の接頭辞があります。
- ユーザー
- 全て
- DBA
サンプル:
select * from dictionary where table_name like 'ALL%'
Mike の例を続けると、スクリプトを生成して制約を有効/無効にすることができます。最初の行の「選択」のみを変更しました。
select 'alter table ' || TABLE_NAME || ' disable constraint ' || CONSTRAINT_NAME || ';'
from all_constraints
where constraint_type='R'
and r_constraint_name in
(select constraint_name
from all_constraints
where constraint_type in ('P','U')
and table_name='<your table here>');
于 2008-09-17T19:22:36.053 に答える
0
データディクショナリテーブルについて説明しているOracleReferenceGuidefor10Gをダウンロードしてください。
上記の答えは良いですが、制約に関連する可能性のある他の表を確認してください。
SELECT * FROM DICT WHERE TABLE_NAME LIKE '%CONS%';
最後に、UIでこのようなものを参照できるToadやSQL Developerなどのツールを入手します。テーブルの使用方法を学ぶ必要がありますが、UIも使用する必要があります。
于 2008-09-17T18:24:58.030 に答える
0
select distinct table_name, constraint_name, column_name, r_table_name, position, constraint_type
from (
SELECT uc.table_name,
uc.constraint_name,
cols.column_name,
(select table_name from user_constraints where constraint_name = uc.r_constraint_name)
r_table_name,
(select column_name from user_cons_columns where constraint_name = uc.r_constraint_name and position = cols.position)
r_column_name,
cols.position,
uc.constraint_type
FROM user_constraints uc
inner join user_cons_columns cols on uc.constraint_name = cols.constraint_name
where constraint_type != 'C'
)
start with table_name = '&&tableName' and column_name = '&&columnName'
connect by nocycle
prior table_name = r_table_name
and prior column_name = r_column_name;
于 2014-12-01T11:57:00.667 に答える