If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > MySQL foreign key info

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-23-09, 12:32
mike_bike_kite mike_bike_kite is offline
vaguely human
 
Join Date: Jun 2007
Location: London
Posts: 2,519
MySQL foreign key info

Does MySQL store FK info in the information schema? The schema seems to imply that it does but there's no useful data in there that I can find. I just want to see what the links are between tables automatically.

Cheers
Reply With Quote
  #2 (permalink)  
Old 08-02-10, 09:31
Andrew Rose Andrew Rose is offline
Registered User
 
Join Date: Jul 2010
Posts: 34
mysql> select version();
+--------------------+
| version() |
+--------------------+
| 5.1.41-3ubuntu12.3 |
+--------------------+
1 row in set (0.00 sec)

mysql> select CONSTRAINT_SCHEMA, TABLE_NAME, COLUMN_NAME, REFERENCED_TABLE_SCHEMA, REFERENCED_TABLE_NAME, REFERENCED_COLUMN_NAME from KEY_COLUMN_USAGE where REFERENCED_TABLE_SCHEMA is not null;
Reply With Quote
  #3 (permalink)  
Old 08-02-10, 09:39
mike_bike_kite mike_bike_kite is offline
vaguely human
 
Join Date: Jun 2007
Location: London
Posts: 2,519
Thank you - better late than never
__________________
Mike
Reply With Quote
  #4 (permalink)  
Old 08-02-10, 19:02
tsx1968 tsx1968 is offline
Registered User
 
Join Date: Aug 2010
Posts: 1
That's AWESOME! It not only took 1.5 years to get an answer, but the OP was actually still around to see the answer the same day. Classic. Just don't ask any questions about the PK...that might take even longer.

Last edited by tsx1968; 08-06-10 at 22:36.
Reply With Quote
  #5 (permalink)  
Old 08-02-10, 19:21
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,609
You gotta love it when the system werks!

-PatP
__________________
In theory, theory and practice are identical. In practice, theory and practice are unrelated.
Reply With Quote
  #6 (permalink)  
Old 08-02-10, 19:24
mike_bike_kite mike_bike_kite is offline
vaguely human
 
Join Date: Jun 2007
Location: London
Posts: 2,519
Quote:
Originally Posted by tsx1968 View Post
That's AWESOME! It not only took 1.5 years to get an answer, but the OP was actually still around to see the answer the same day. Classic. Just don't ask any questions about the PK...that might take even longer.
After the 1st year I was beginning to give up hope but I knew I just had to hang in there
__________________
Mike
Reply With Quote
  #7 (permalink)  
Old 08-03-10, 04:05
Andrew Rose Andrew Rose is offline
Registered User
 
Join Date: Jul 2010
Posts: 34
Hi, I guess it may seem a little weird to have replied to such an old thread. I came across it after reading Mikes thread on OTLT/EAV and then taking a look at his thread history for any other gems :-D
Reply With Quote
  #8 (permalink)  
Old 08-03-10, 04:09
Andrew Rose Andrew Rose is offline
Registered User
 
Join Date: Jul 2010
Posts: 34
Quote:
Originally Posted by tsx1968 View Post
That's AWESOME! It not only took 1.5 years to get an answer, but the OP was actually still around to see the answer the same day. Classic. Just don't ask any questions about the PK...that might take even longer.

mysql> select CONSTRAINT_SCHEMA, TABLE_SCHEMA, COLUMN_NAME from KEY_COLUMN_USAGE where CONSTRAINT_NAME = 'PRIMARY';

Reply With Quote
  #9 (permalink)  
Old 08-03-10, 04:11
Andrew Rose Andrew Rose is offline
Registered User
 
Join Date: Jul 2010
Posts: 34
Should be TABLE_NAME instead of TABLE_SCHEMA, sorry.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On