+ Reply to Thread
Results 1 to 3 of 3

Thread: MySQL: FOREIGN KEYS

  1. #1
    cursillo's Avatar
    cursillo is offline x10Hosting Member cursillo is an unknown quantity at this point
    Join Date
    Apr 2008
    Posts
    10

    Question MySQL: FOREIGN KEYS

    Manu, From Teruel (Spain):cool:

    Hi everyone!

    I'm trying to build a BD with 3 relational tables, something like: C = A + B.

    The A and B tables are InnoDB and they're OK, my problem comes with the last one (C)

    I can't use FOREIGN KEY. Is it because I'm using MySQL Admin? Is there a limitation on the server? Am I writing something wrong? :dunno:

    Thanks for your help. (Excuse me for my poor English)

    That's my code:

    CREATE TABLE score (
    id INT NOT NULL AUTO_INCREMENT,
    id_composer INT NOT NULL,
    id_work INT NOT NULL,
    PRIMARY KEY (id),
    FOREIGN KEY (id_composer) REFERENCES composer (id),
    FOREIGN KEY (id_work) REFERENCES work (id)
    );
    ENGINE = InnoDB;

  2. #2
    ah-blabla's Avatar
    ah-blabla is offline x10 Lieutenant ah-blabla is an unknown quantity at this point
    Join Date
    Sep 2009
    Posts
    375

    Re: MySQL: FOREIGN KEYS

    I don't have much SQL experience, but I'll try help:
    Try removing the ; after the last bracket, i.e. the last three lines should be:
    Code:
    FOREIGN KEY (id_work) REFERENCES work (id)
    )
    ENGINE = InnoDB;
    All the examples on this page don't have that semicolon, so that *could* be causing the problem. Also try posting the error message you get. (Posting all the sql code you run beforehand would also be useful to help debug the problem.)

  3. #3
    cursillo's Avatar
    cursillo is offline x10Hosting Member cursillo is an unknown quantity at this point
    Join Date
    Apr 2008
    Posts
    10

    Re: MySQL: FOREIGN KEYS

    Problem solved

    first: CREATE TABLE (MyISAM)
    second: ALTER TABLE TYPE:InnoDB


    Thanks for your help!
    Last edited by cursillo; 10-27-2009 at 01:07 PM. Reason: Problem solved

+ Reply to Thread

Similar Threads

  1. [PHP] MySQL and PHP
    By Bryon in forum Tutorials
    Replies: 43
    Last Post: 03-24-2011, 08:27 AM
  2. Replies: 14
    Last Post: 09-29-2008, 08:07 PM
  3. New Site-Suggestions?
    By mnoutside in forum Review My Site
    Replies: 9
    Last Post: 08-27-2008, 08:01 AM
  4. Foreign keys don't stick
    By sevorak in forum Free Hosting
    Replies: 1
    Last Post: 10-03-2007, 11:36 PM
  5. Have a problem with my forum
    By tikloos in forum Scripts & 3rd Party Apps
    Replies: 43
    Last Post: 01-19-2006, 02:14 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers