20
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

MySQLでinformation_schemaから外部キー参照を確認する時のメモ

Posted at

外部キーの一覧を見たい、でもテーブルの定義を1個1個見ていくのは面倒。
そんな時にinformation_schemaから制約を取得できるので自分用メモ。

table_constraints

MySQLで外部キーをはっているテーブルを調査するのに使える

select * from `information_schema`.table_constraints
where
table_schema = "{スキーマ名}" and
constraint_type="FOREIGN KEY"
;

key_column_usage

特定のテーブルへの外部キーをはってあるテーブルの一覧を取得できる

select * from information_schema.key_column_usage
where
  constraint_schema='{スキーマ名}' and
  referenced_table_name='table_name'
;
20
10
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
20
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?