Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Quick SQL question

  • 17-04-2010 08:08PM
    #1
    Registered Users, Registered Users 2 Posts: 427 ✭✭


    Hi,
    I am getting an error when creating a table of mine due to a foreign key in a MYSQL database.

    e.g.
    Tables:
    A
    idA PK

    B
    idB
    FK references A (idB->idA)

    C
    idC
    FK reference A (idC->idA)

    Is there some problem with this? I seem to be able to make one table referencing A with a foreign key but I cannot make two(Error 121).

    Thanks.


Comments

  • Closed Accounts Posts: 3,357 ✭✭✭Beano


    what error are you getting?


  • Moderators, Politics Moderators, Paid Member Posts: 44,253 Mod ✭✭✭✭Seth Brundle


    Double check dataypes on common fields.
    Is the table containing the PK created before the FK table?
    stick up your code!

    Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/ .



  • Registered Users, Registered Users 2 Posts: 427 ✭✭Kevo


    Ok so I explained that rather poorly. I oversimplified the problem. I just wanted to know was I making a very obvious error. If not it must be syntax.


    I will post code in a few mins.


    EDIT:
    Fixed my problem. All my FKs had the same name. I thought this would be ok since they are in different tables but I guess that since they reference the same table it becomes a problem.


  • Moderators, Politics Moderators, Paid Member Posts: 44,253 Mod ✭✭✭✭Seth Brundle


    Cool.
    FYI any structural item within a DB schema can be regarded as an object and gets a unique name.

    Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/ .



Advertisement