Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Cann't add foreign key to a table

roymakaayFeb 10 2009 — edited Feb 10 2009
Hi

Ihave two tables class,and students table as following

sql>desc class
Name Null? Type
----------------------------------------- -------- ----------------------------
CLASS_ID NOT NULL NUMBER(4)
CLASS_NAME VARCHAR2(100)
SEAT_NUMBER NUMBER
STUD_ID NUMBER

SQL> desc students
Name Null? Type
----------------------------------------- -------- ----------------------------
STUD_ID NOT NULL NUMBER(4)
STUD_NAME NOT NULL VARCHAR2(50)
BIRTHDATE DATE
ADDRESS VARCHAR2(100)
GENDER VARCHAR2(7)
GRADE NUMBER
STUD_PHONE_NUMBER NUMBER

stud_id is primary key in students table ,and it's added to the class table to make relationship

Iwant to add a foreign key(stud_name ) to table class so I did the following commands:-
 
sql> alter table class add   foreign key(stud_name)references students(stud_name);
error:-
ORA-00904: "STUD_NAME": invalid identifier
SQL>   alter table class add (constriant fk_students)foreign key(stud_name)references  students(stud
_name);
error:-
ORA-01735: invalid ALTER TABLE option.
Ihave though the problem from primary kry constraint ,so I dropped stud_id column from class table ,and then runned the previous command again but same error getted (.ORA-01735: invalid ALTER TABLE option).
any help please
thanks in advance.
This post has been answered by 513949 on Feb 10 2009
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 10 2009
Added on Feb 10 2009
1 comment
305 views