18 messages in com.mysql.lists.javaRe: Getting foreign keys.
FromSent OnAttachments
Mofeed Shahin11 Dec 2003 22:44 
Jeff Newmiller12 Dec 2003 10:20 
Chris McGowan12 Dec 2003 10:38 
Mark Matthews12 Dec 2003 10:55 
Chris McGowan12 Dec 2003 11:52 
Mofeed Shahin14 Dec 2003 15:08 
Christian Mack17 Dec 2003 10:02 
Mofeed Shahin17 Dec 2003 14:31 
Susidzaimah Pg Sulaiman30 Jan 2004 00:38 
Scott Queen30 Jan 2004 06:43 
Mike Markovich30 Jan 2004 07:12 
Susidzaimah Pg Sulaiman31 Jan 2004 17:26 
Susidzaimah Pg Sulaiman31 Jan 2004 17:27 
Scott Queen31 Jan 2004 19:07 
Keith Hatton02 Feb 2004 01:26 
Mike Markovich02 Feb 2004 07:49 
Susidzaimah Pg Sulaiman02 Feb 2004 23:40 
Susidzaimah Pg Sulaiman03 Feb 2004 19:01 
Subject:Re: Getting foreign keys.
From:Chris McGowan (Chri@Colorado.edu)
Date:12/12/2003 10:38:57 AM
List:com.mysql.lists.java

Mofeed,

Jeff's correct. You'll need to use InnoDB tables for foreign keys to work. But it seems useless to use foreign keys unless you're using Constraints. Just add type=InnoDB to the end of your create table() syntax and it should work:

CREATE TABLE Student (Stud_ID INT) TYPE=innodb;

I messed around with your problem and couldn't get J/Connector to show anything for Foreign Keys. But then again, I'm unaware of any MySQL query/function that actually shows foreign key information, except for: SHOW CREATE TABLE table_name;

It may be a lost cause :(

On Fri, 12 Dec 2003, Mofeed Shahin wrote:

Hey guys,

I've just started to play with MySQL, and am trying to get something I wrote to talk to it, but I'm having problems getting foreign key information out of the database.

[...]

The Tables are created like so :

CREATE TABLE Student ( Student_ID INT PRIMARY KEY, First_Name varchar(50), Last_Name varchar(50), UNIQUE (First_Name, Last_Name) );

CREATE TABLE Address ( First_Name varchar(50), Last_Name varchar(50), Address varchar(50), PRIMARY KEY (First_Name, Last_Name), FOREIGN KEY (First_Name, Last_Name) REFERENCES student (First_Name, Last_Name) );

The problem is that when I do meta.getImportedKeys(...), it returns an empty set. I've tried the same thing, but using a single column foreign key, but that still returns an empty set.....

MySQL tables don't support foreign keys... the syntax just gets swallowed.

Try InnoDB tables... RTF-MySQL-M. I don't know if Connector/J will dig up the information you want, but until foreign keys are actually present you can't expect to get information on them.

-------------------------------------------------------------------------- - Jeff Newmiller The ..... ..... Go Live... DCN:<jdne@dcn.davis.ca.us> Basics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/Batteries O.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...2k

-------------------------------------------------------------------------- -