Results 1 to 4 of 4
  1. #1
    Join Date
    Sep 2005
    Posts
    67

    Unanswered: show foreign keys

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

    Thanks!

  2. #2
    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;

  3. #3
    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?

  4. #4
    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,

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •