Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
2
Help us understand the problem. What is going on with this article?
@a-nishimura

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

More than 1 year has passed since last update.

外部キーの一覧を見たい、でもテーブルの定義を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'
;
2
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
a-nishimura
フリーランスプログラマ。主にweb系のソフトウェアエンジニアです。日々の学びや気づきなどブログ書いてます。フットサル、筋トレ、日向坂46、YouTubeが好きです。

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
2
Help us understand the problem. What is going on with this article?