unable to add foriegn key constaint

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • raghunana
    New Member
    • Mar 2007
    • 1

    unable to add foriegn key constaint

    hello friends,
    i am a beginer.I was unable to add a foriegn key constraint to my NAMES table which refers my EMPLOYEE TABLE

    Code:
    SQL> desc employee
     Name                                      Null?    Type
     ----------------------------------------- -------- ----------------------------
     FNAME                                              VARCHAR2(10)
     LNAME                                              VARCHAR2(10)
     SSN                                       NOT NULL NUMBER(4)
     ADDRESS                                            VARCHAR2(50)
     SEX                                                VARCHAR2(1)
     SALARY                                             NUMBER(5)
     SUPERSSN                                           NUMBER(5)
     DNO                                                NUMBER(1)
    
    SQL> desc names
     Name                                      Null?    Type
     ----------------------------------------- -------- ----------------------------
     NAME                                               VARCHAR2(5)
     NSSN                                               NUMBER(4)
    
    SQL> alter table names add constraint nn8 foriegn key(nssn) references employee(ssn);
    alter table names add constraint nn8 foriegn key(nssn) references employee(ssn)
                                                     *
    ERROR at line 1:
    ORA-01735: invalid ALTER TABLE option
  • Dave44
    New Member
    • Feb 2007
    • 153

    #2
    Originally posted by raghunana
    hello friends,
    i am a beginer.I was unable to add a foriegn key constraint to my NAMES table which refers my EMPLOYEE TABLE

    Code:
    SQL> desc employee
     Name                                      Null?    Type
     ----------------------------------------- -------- ----------------------------
     FNAME                                              VARCHAR2(10)
     LNAME                                              VARCHAR2(10)
     SSN                                       NOT NULL NUMBER(4)
     ADDRESS                                            VARCHAR2(50)
     SEX                                                VARCHAR2(1)
     SALARY                                             NUMBER(5)
     SUPERSSN                                           NUMBER(5)
     DNO                                                NUMBER(1)
    
    SQL> desc names
     Name                                      Null?    Type
     ----------------------------------------- -------- ----------------------------
     NAME                                               VARCHAR2(5)
     NSSN                                               NUMBER(4)
    
    SQL> alter table names add constraint nn8 foriegn key(nssn) references employee(ssn);
    alter table names add constraint nn8 foriegn key(nssn) references employee(ssn)
                                                     *
    ERROR at line 1:
    ORA-01735: invalid ALTER TABLE option

    Just remember that a foreign key must reference either a unique key or primary key on another table. (i cant see what your indexes and primary keys are here)

    **but in this case the immediate problem appears to be your spelling of the word foreign (not foriegn) ** :)

    Comment

    • debasisdas
      Recognized Expert Expert
      • Dec 2006
      • 8119

      #3
      your problem is poor spelling
      use FOREIGN KEY
      YOUR PROBLEM WILL BE SOLVED

      note:-foreign key refers to a Primary key or at least an Unique field.
      Take care in future.

      Comment

      Working...