0

すべての外部キーの概要を把握できる select ステートメントを作成しようとしています。次のようになります。

表 1 | FK_Value | 表 2 | FK_値

「user_constraints」テーブルを使用する方法が必要であることがわかりましたが、助けが必要です。

4

2 に答える 2

0

これはSQL2008でうまくいきました(2005はありません)

参照テーブルと列名のリストを取得するには...

select t.name as TableWithForeignKey, fk.constraint_column_id as FK_PartNo , c.name as ForeignKeyColumn 
from sys.foreign_key_columns as fk
inner join sys.tables as t on fk.parent_object_id = t.object_id
inner join sys.columns as c on fk.parent_object_id = c.object_id and fk.parent_column_id = c.column_id
where fk.referenced_object_id = (select object_id from sys.tables where name = 'TableOthersForeignKeyInto')
order by TableWithForeignKey, FK_PartNo
于 2014-03-07T09:53:17.920 に答える