• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

retriving two primary keys

 
Shobana Sukumar
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i need to work with a table which has two primary keys.

when i use DataBaseMetaData.getPrimaryKeys() i can extract the value if theres one primary key.but what if two primary keys are there.any suggestions?
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why can't you use DatabaseMetaData.getPrimaryKeys() to deal with a primary key that has two columns? It looks like this method returns a ResultSet. Have you checked how many rows are in this result set in the situation you describe? If it has multiple rows, then each row probably represents one column in the primary key.

HTH

Layne
 
stu derby
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Shobana Sukumar:
i need to work with a table which has two primary keys.



To be precise, that's impossible. A table can have only one primary key, that's the basic fundamental meaning of "primary". You can however, have a primary key composed of more than one column. A primary key is nothing more or less than a unique index with a very special (primary) relationship to the table; most databases implement it that way.

The previous response appears to be on the right track for "how do I work with a table which has a primary key with multiple columns?".
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic