1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Development Urgent! SQL help with foreign keys!!!

Discussion in 'Software' started by julianmartin, 26 Mar 2009.

  1. julianmartin

    julianmartin resident cyborg.

    Joined:
    25 Jul 2004
    Posts:
    3,562
    Likes Received:
    126
    Hi guys, sorry this is obviously a coursework help thread - I might as well come out with it!

    Really struggling with SQL here, have a deadline in a few hours and towards the end of this coursework I have stumbled across a pretty big problem with foreign keys.

    When I try to call a foreign key, say cart_id from table Item, it just comes up blank.

    What have I done wrong?

    Any help would be SERIOUSLY appreciated as I'm going nuts here.....
     
  2. Alex6969

    Alex6969 If it's fixed, I can break it.

    Joined:
    30 May 2008
    Posts:
    24
    Likes Received:
    1
    It's been a while but let's see if I still have the magic touch.

    Try adding "CONSTRAINT FK Cart_ID" in your create table code. That tells the DB that "Cart_ID" is the foreign key for that table. Also throw in a "CONSTRAINT PK 'whatever'". This will give your table a Primary key as well.

    Also, depending on what software you are using, Oracle, M$ SQL Server Mgnt. Studio, or Access, have different ways you need access data from tables. Ensure that you are referencing the table correctly, etc, etc. I won't go on about all that since I'm sure you know that already.

    Good luck!
     
    julianmartin likes this.
  3. julianmartin

    julianmartin resident cyborg.

    Joined:
    25 Jul 2004
    Posts:
    3,562
    Likes Received:
    126
    Thanks Alex...transpires FK's aren't as useful as they should be in the MySQL version that our uni runs....explaining my loss of understanding, but also meaning my repeated efforts were futile. Great!

    Thanks again though. Rep+ :)
     

Share This Page