Gossamer Forum
Home : General : Databases and SQL :

Re: [Stealth] How to get primary key for table in Oracle?

Quote Reply
Re: [Stealth] How to get primary key for table in Oracle? In reply to
I had posted this question to dbi-users as well (though it wasn't a dbi question, really), and now found a solution that works:

my $sql = qq|select a.column_name from user_cons_columns a, user_constraints b where a.constraint_name = b.constraint_name and a.table_name = b.table_name and b.table_name = 'TABLE_NAME' and b.constraint_type = 'P'|;

$sth = $dbh->prepare($sql);
$sth->execute();
while (my $hash_ref = $sth->fetchrow_hashref) {
my $key = $hash_ref->{COLUMN_NAME};
print "$key"; # yep: the primary key name!

}

(never mind the clumsy hashref, it's the rest that counts.)



Cheers,
kellner
Subject Author Views Date
Thread; hot thread How to get primary key for table in Oracle? kellner 64823 Sep 6, 2002, 7:20 AM
Thread; hot thread Re: [kellner] How to get primary key for table in Oracle?
Aki 63968 Sep 6, 2002, 8:30 AM
Thread; hot thread Re: [Aki] How to get primary key for table in Oracle?
kellner 64192 Sep 6, 2002, 8:59 AM
Post; hot thread Re: [kellner] How to get primary key for table in Oracle?
cornball 63937 Sep 6, 2002, 9:04 AM
Post; hot thread Re: [kellner] How to get primary key for table in Oracle?
Paul 63932 Sep 6, 2002, 9:05 AM
Thread; hot thread Re: [kellner] How to get primary key for table in Oracle?
Stealth 64164 Sep 6, 2002, 9:20 AM
Thread; hot thread Re: [Stealth] How to get primary key for table in Oracle?
kellner 64283 Sep 6, 2002, 9:43 AM
Thread; hot thread Re: [kellner] How to get primary key for table in Oracle?
Stealth 64162 Sep 6, 2002, 10:06 AM
Thread; hot thread Re: [Stealth] How to get primary key for table in Oracle?
kellner 64078 Sep 6, 2002, 10:13 AM
Thread; hot thread Re: [kellner] How to get primary key for table in Oracle?
Aki 64106 Sep 6, 2002, 10:20 AM
Thread; hot thread Re: [Aki] How to get primary key for table in Oracle?
kellner 64107 Sep 6, 2002, 10:24 AM
Thread; hot thread Re: [kellner] How to get primary key for table in Oracle?
Paul 64062 Sep 6, 2002, 10:34 AM
Post; hot thread Re: [Paul] How to get primary key for table in Oracle?
Stealth 63984 Sep 6, 2002, 11:57 AM
Thread; hot thread Re: [kellner] How to get primary key for table in Oracle?
cornball 64139 Sep 6, 2002, 10:42 AM
Thread; hot thread Re: [kode] How to get primary key for table in Oracle?
kellner 64029 Sep 6, 2002, 11:59 AM
Thread; hot thread Re: [kellner] How to get primary key for table in Oracle?
cornball 64062 Sep 6, 2002, 12:05 PM
Thread; hot thread Re: [kode] How to get primary key for table in Oracle?
kellner 63953 Sep 6, 2002, 12:13 PM
Thread; hot thread Re: [kellner] How to get primary key for table in Oracle?
604 63954 Sep 6, 2002, 1:58 PM
Post; hot thread Re: [TheStone] How to get primary key for table in Oracle?
beni333 63324 Jan 9, 2003, 2:44 AM
Thread; hot thread Re: [kellner] How to get primary key for table in Oracle?
anup123 62900 Mar 23, 2003, 12:33 PM
Thread; hot thread How to get primary key for table in Oracle?
sunita_gateway 61545 Mar 23, 2004, 12:58 AM
Thread; hot thread Re: [sunita_gateway] How to get primary key for table in Oracle?
hongtao 56865 Apr 23, 2008, 11:38 AM
Post; hot thread Re: [hongtao] How to get primary key for table in Oracle?
dan 56712 Apr 23, 2008, 3:02 PM