Обсуждение: Foreign Key Identification
Hello All, Is there any means to list out the foreign key tables which are liked with a primary key? What i want to do is something as follows: TableA with primary key TableAPK TableB with Foreign key TableAPK TableC with Foreign Key TableAPK Waht i want to get is select tablename from ? where Foreign key = TableAPK and this should list me TableB TableC is there any way to get this? Thanks in advance With Regards Ashish Karalkar ____________________________________________________________________________________ Do you Yahoo!? Everyone is raving about the all-new Yahoo! Mail beta. http://new.mail.yahoo.com
am Wed, dem 10.01.2007, um 8:23:28 -0800 mailte Ashish Karalkar folgendes: > Hello All, > Is there any means to list out the foreign key tables > which are liked with a primary key? > > is there any way to get this? Take a look into the pg_depend - table. http://www.postgresql.org/docs/8.1/interactive/catalog-pg-depend.html Andreas -- Andreas Kretschmer Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr: -> Header) GnuPG-ID: 0x3FFF606C, privat 0x7F4584DA http://wwwkeys.de.pgp.net
"A. Kretschmer" <andreas.kretschmer@schollglas.com> writes: > am Wed, dem 10.01.2007, um 8:23:28 -0800 mailte Ashish Karalkar folgendes: >> Is there any means to list out the foreign key tables >> which are liked with a primary key? > Take a look into the pg_depend - table. I think there's an information_schema view that would give you this without getting so cozy with implementation details as to look in pg_depend ... regards, tom lane
am Wed, dem 10.01.2007, um 12:17:25 -0500 mailte Tom Lane folgendes: > "A. Kretschmer" <andreas.kretschmer@schollglas.com> writes: > > am Wed, dem 10.01.2007, um 8:23:28 -0800 mailte Ashish Karalkar folgendes: > >> Is there any means to list out the foreign key tables > >> which are liked with a primary key? > > > Take a look into the pg_depend - table. > > I think there's an information_schema view that would give you this > without getting so cozy with implementation details as to look in > pg_depend ... I have no doubt, but unfortunately i don't know details. Can you help? Andreas -- Andreas Kretschmer Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr: -> Header) GnuPG-ID: 0x3FFF606C, privat 0x7F4584DA http://wwwkeys.de.pgp.net
From: Ashish Karalkar <ashish_karalkar ( at ) yahoo ( dot ) com> * To: pgsql-general ( at ) postgresql ( dot ) org * Subject: Foreign Key Identification * Date: Wed, 10 Jan 2007 08:23:28 -0800 (PST) ________________________________________________________________ Hello All, Is there any means to list out the foreign key tables which are liked with a primary key? What i want to do is something as follows: ... select tablename from ? where Foreign key = TableAPK and this should list me I needed to do something similar. I wrote some views to do this and packaged 'em up as something I call pgutils. See: http://archives.postgresql.org/pgsql-general/2006-11/msg00752.php http://harts.net/reece/pgutils/ -Reece -- Reece Hart, http://harts.net/reece/, GPG:0x25EC91A0 ./universe -G 6.672e-11 -e 1.602e-19 -protonmass 1.673e-27 -uspres bush kernel warning: universe consuming too many resources. Killing. universe killed due to catastrophic leadership. Try -uspres carter.
Thank You Guys, For your valuable suggestions. Out of the suggestion to investigate in to PG_depane was cumbersome , yes there is a view in information schema called information_schema.referential_constraints which gives same details in terms of foreign keys and primary keys and is usefull if u have strict nameing convention for foreign key and primary key in order to arive at table name.. Reece pgutil is excellent to get the all required information on foreign key tables and primary key tables. With Regards Ashish Karalkar --- Reece Hart <reece@harts.net> wrote: > From: Ashish Karalkar <ashish_karalkar ( at > ) yahoo ( dot ) com> > * To: pgsql-general ( at ) postgresql > ( dot ) org > * Subject: Foreign Key Identification > * Date: Wed, 10 Jan 2007 08:23:28 > -0800 (PST) > > > ________________________________________________________________ > Hello All, > Is there any means to list out the foreign > key tables > which are liked with a primary key? > What i want to do is something as follows: > ... > select tablename from ? where Foreign key = > TableAPK > and this should list me > > > I needed to do something similar. I wrote some views > to do this and > packaged 'em up as something I call pgutils. See: > > http://archives.postgresql.org/pgsql-general/2006-11/msg00752.php > > http://harts.net/reece/pgutils/ > > > -Reece > > -- > Reece Hart, http://harts.net/reece/, GPG:0x25EC91A0 > ./universe -G 6.672e-11 -e 1.602e-19 -protonmass > 1.673e-27 -uspres bush > kernel warning: universe consuming too many > resources. Killing. > universe killed due to catastrophic leadership. Try > -uspres carter. > > ____________________________________________________________________________________ Yahoo! Music Unlimited Access over 1 million songs. http://music.yahoo.com/unlimited