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 > show foreign keys

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-27-05, 11:01
djuritz djuritz is offline
Registered User
 
Join Date: Sep 2005
Posts: 67
show foreign keys

How can I do to make a SELECT of FK's of a given table?

Thanks!
Reply With Quote
  #2 (permalink)  
Old 09-27-05, 11:16
tombell tombell is offline
Registered User
 
Join Date: Jun 2005
Posts: 23
Do you mean how to show the foreign keys defined for a table?
If so
Code:
SHOW CREATE TABLE tablename;
Reply With Quote
  #3 (permalink)  
Old 09-27-05, 11:50
djuritz djuritz is offline
Registered User
 
Join Date: Sep 2005
Posts: 67
Quote:
Originally Posted by tombell
Do you mean how to show the foreign keys defined for a table?
If so
Code:
SHOW CREATE TABLE tablename;
Yes, but I need to drop all constraints of a database.
I thought I could do a script in PHP that loops the tables and foreach table, deletes its foreign keys.

Is there any easier way?

Or is there any way to toogle from InnoDB to MyISAM?
Reply With Quote
  #4 (permalink)  
Old 09-29-05, 12:51
expert-db expert-db is offline
Registered User
 
Join Date: Mar 2004
Posts: 33
Lightbulb

Hi,

In MySQL 5. is very easy with information schema, check this query :

SELECT *
FROM information_schema.KEY_COLUMN_USAGE
WHERE TABLE_SCHEMA ='mydb' AND TABLE_NAME ='mytable' AND
CONSTRAINT_NAME <>'PRIMARY' AND REFERENCED_TABLE_NAME is not null


Regards,
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