Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Finding the primary key

 
Rik Sweeney
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to allow a user to perform joins on primary/foreign key pairs. Is there anyway I can find a foreign key in a table and it's matching primary key table? I really need the columns from both the tables aswell. Is there an easy way to do this?
 
Jamie Robertson
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
DatabaseMetaData.getCrossReference should do the trick for you. If your driver does not implement this method then you might have to hit the database system tables to get the info which are database specific.
also DatabaseMetaData.getImportedKeys() and DatabaseMetaData.getExportedKeys() could be useful too.
Jamie
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic