What I am trying to do ?
I am trying to create two tables and at the same time i am trying to link them together using foreign and primary keys. However I successfully create my parent table ( Student with primary key ) but failed to create child table ( Attendence with foreign key ).
What is the problem ?
I get the following error while creating Attendence table:
ERROR at line 5: ORA-01748: only simple column names allowed here
My code:
Student table:
create table Student ( ST_ROLLNO NUMBER(6) constraint s_pk primary key, ST_NAME VARCHAR(30) not null, ST_ADDRESS varchar(35) not null );
Attendence table:
create table Attendence ( ST_ROLLNO NUMBER(6), ST_DATE VARCHAR(30) not null, ST_PRESENT_ABSENT varchar(1) not null, constraint f_pk Attendence.ST_ROLLNO foreign key references Student(ST_ROLLNO) );
Advertisement
Answer
Your foreign key constraint syntax is wrong; it should be:
constraint f_pk foreign key (ST_ROLLNO) references Student(ST_ROLLNO)
You are preceding the FK column name with the table name, which is wrong in itself, but also have it in the wrong place.
create table Student ( ST_ROLLNO NUMBER(6) constraint s_pk primary key, ST_NAME VARCHAR(30) not null, ST_ADDRESS varchar(35) not null ); Table STUDENT created. create table Attendence ( ST_ROLLNO NUMBER(6), ST_DATE VARCHAR(30) not null, ST_PRESENT_ABSENT varchar(1) not null, constraint f_pk foreign key (ST_ROLLNO) references Student(ST_ROLLNO) ); Table ATTENDENCE created.