Menampilkan Foreign Key dari Query

Seorang teman lama tiba-tiba bertanya via YM:

sang teman: meh takon
sang teman: query nggo ngerti struktur tabel opo y ? mysql

sang teman: sing iso menampilkan foreign key ?

Bingung? :mrgreen:
Terjemahannya kira-kira:

sang teman: mau tanya
sang teman: query mysql untuk mengetahui struktur tabel apa ya?

sang teman: yang bisa menampilkan foreign key?

Setelah utak-atik sedikit dan hasil diskusi bersama sang teman, akhirnya didapati query berikut:

SELECT constraint_name, table_name, column_name, referenced_table_name, referenced_column_name  
    FROM information_schema.key_column_usage
    WHERE table_schema='nama_database_anda'
    AND table_name='nama_tabel_anda';

Semoga berguna 😉
Ada yang punya cara lain? 🙄

Diilhami dari http://forums.mysql.com/read.php?10,114819,114822#msg-114822

Published by Eric Gunawan

Happiness Engineer. WordPress Ambassador. Remote Worker. Soccer News Follower. Movie Lover. Proud Father. Lucky Husband.

One thought on “Menampilkan Foreign Key dari Query

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: