BowerStudios.com

  • My Lab
  • Family
  • Friends
  • Professional
  • About
Home

Find foreign keys referencing a table: postgres

daniel —Mon, 12/17/2012 - 4:05pm

  • SQL

SELECT tc.table_schema, tc.constraint_name, tc.table_name, kcu.column_name, ccu.table_name
AS foreign_table_name, ccu.column_name AS foreign_column_name
FROM information_schema.table_constraints tc
JOIN information_schema.key_column_usage kcu ON tc.constraint_name = kcu.constraint_name
JOIN information_schema.constraint_column_usage ccu ON ccu.constraint_name = tc.constraint_name
WHERE constraint_type = 'FOREIGN KEY'
AND ccu.table_name='myTableName'

From: errorbank.blogspot.com

  • Log in to post comments

Navigation

  • Search
  • Recent content
  • Contact Me
  • Mail
  • Pass Hasher
  • Bower Studios Admin

Quotes

daniel —Fri, 08/25/2006 - 10:16pm

I know you believe you understand what you think I said, but I'm not sure you realize that what you heard is not what I meant.

—

Richard Nixon

  • Log in to post comments
  • daniel's quotes

Popular content

Last viewed:

  • Git Merge Conflicts
  • Solr Near Realtime Indexing
  • Thomas A. Edison
  • Groovy from cron
  • Black Bean and Corn Pasta with Chicken

Copyright 2021 Daniel Bower
  • My Lab
  • Family
  • Friends
  • Professional
  • About