Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 2008
    Posts
    8

    Unanswered: foreign keys..... ERROR!!!!! :(

    Okay I am doing something very simple but for some reason I get an Invlaid Indentifier error, Yes i know what this means and why i am getting it but I dont understand why? from what i can see my code is correct?

    An example of my table creating..

    CREATE TABLE flight
    (flightno NUMBER (2) PRIMARY KEY,
    airline VARCHAR (15),
    flightdate DATE)


    CREATE TABLE holiday
    (holidayId NUMBER(2) PRIMARY KEY,
    destination CHAR (15),
    numdays NUMBER (2) DEFAULT 7,
    basicprice NUMBER (2),
    FOREIGN KEY (flightno) REFERENCES flight(flightno));

    OR

    if i use the

    ALTER TABLE holiday ADD FOREIGN KEY(flightno)
    REFERENCES flight(flightno);

    same thing happens

    but its says that flightno, is invaid? any ideas why? i cant get add foreign keys to any of my tables?

    Many Thanks

  2. #2
    Join Date
    Mar 2008
    Posts
    8
    Even if i used the


    ALTER TABLE holiday ADD FOREIGN KEY(flightno)
    REFERENCES flight(flightno);

    it still doesnt work

  3. #3
    Join Date
    Nov 2003
    Posts
    2,935
    Provided Answers: 12
    You don't have a column called flightno in your holiday table.

    That should be
    Code:
    CREATE TABLE holiday
    (
    holidayId NUMBER(2) PRIMARY KEY,
    flightno NUMBER(2) NOT NULL,
    destination CHAR (15),
    numdays NUMBER (2) DEFAULT 7,
    basicprice NUMBER (2),
    FOREIGN KEY (flightno) REFERENCES flight(flightno)
    );
    Are you sure you want to use NUMBER(2)?
    That means that the max. Number you can store is 99.

  4. #4
    Join Date
    Mar 2008
    Posts
    8
    shammat, thank you. Sorry i am very new to SQL only been doing at a little while. I think your correct about the (2) maybe it should be 5... Let me give that a go and see if it works.

  5. #5
    Join Date
    Nov 2006
    Posts
    4
    may be you should learn some sql syn?

Posting Permissions

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