0 Replies Latest reply: Feb 24, 2012 4:45 AM by 919782 RSS

    Error 00904 trying to alter table ... ?!

    919782
      I'm running a script to create a table, the primary key of that table will then be used in an Alter Table command to make it a foreign key in an already exisiting table. Code:

      CREATE TABLE Category
      (
      CATCODE VARCHAR2(3),
      CatDesc VARCHAR2(11) NOT NULL,
      CONSTRAINT Category_CATCODE_pk PRIMARY KEY(CATCODE)
      );

      INSERT INTO Category(CATCODE, CatDesc) VALUES('BUS','Business');
      INSERT INTO Category(CATCODE, CatDesc) VALUES('CHN','Children');
      INSERT INTO Category(CATCODE, CatDesc) VALUES('COK','Cooking');
      INSERT INTO Category(CATCODE, CatDesc) VALUES('COM','Computer');
      INSERT INTO Category(CATCODE, CatDesc) VALUES('FAL','Family Life');
      INSERT INTO Category(CATCODE, CatDesc) VALUES('FIT','Fitness');
      INSERT INTO Category(CATCODE, CatDesc) VALUES('SEH','Self Help');
      INSERT INTO Category(CATCODE, CatDesc) VALUES('LIT','Literature');

      ALTER TABLE books ADD CONSTRAINT books_Category_fk FOREIGN KEY (CATCODE) REFERENCES Category(CATCODE);



      And the error:
      Error starting at line 20 in command:
      ALTER TABLE books ADD CONSTRAINT books_Category_fk FOREIGN KEY (CATCODE) REFERENCES Category(CATCODE)
      Error report:
      SQL Error: ORA-00904: "CATCODE": invalid identifier
      00904. 00000 - "%s: invalid identifier"
      *Cause:   
      *Action:


      I have no idea what is wrong with my code. I successfully make my table and insert the data, why is it telling me CatCode is an invalid identifier?...