SQL - ORA-01748 - Only Simple Column Names Allowed Here in Oracle - Stack Overflow
SQL - ORA-01748 - Only Simple Column Names Allowed Here in Oracle - Stack Overflow
Asked 5 years, 11 months ago Modified 3 years, 1 month ago Viewed 28k times
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
3
primary keys. However I successfully create my parent table ( Student with primary key ) but failed to
create child table ( Attendence with foreign key ).
My code:
Student table:
Attendence table:
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)
);
sql oracle
Share Improve this question Follow edited Dec 6, 2017 at 17:11 asked Dec 6, 2017 at 16:55
Ahtisham
9,368 4 43 58
1 A column name is "simple" if it is not qualified with a table name. Constraints, at least in Oracle, cannot span across
tables; an out-of-line constraint, like you are defining, must be on a column (or combination of columns) in the
same table you are defining. So it makes no sense to qualify the name or names of the constrained column(s) with
the table name (which is understood); and the syntax prohibits it, to make it crystal clear. – user5683823 Dec 6, 2017
at 17:40
2 Answers Sorted by: Highest score (default)
You are preceding the FK column name with the table name, which is wrong in itself, but also have it in
the wrong place.
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)
);
Share Improve this answer Follow edited Dec 6, 2017 at 18:08 answered Dec 6, 2017 at 16:58
Alex Poole
185k 11 181 321
Do you know how to perform DML operation on a table whoes column is type obeject ? – Ahtisham Dec 6, 2017 at
17:14
1 @Ahtisham - yes, but that doesn't have anything to do with this question. There are plenty of examples around,
depending on exactly what you're doing (including in the documentation), but if you try to follow those and can't
make it work then you'll need to ask a new question. – Alex Poole Dec 6, 2017 at 17:19
3 Or you can include the FK in the column definition and inherit the datatype: st_rollno constraint f_pk
references student(st_rollno) . – William Robertson Dec 6, 2017 at 17:32
1 @Ahtisham - that's irrelevant to the issue you were having, and won't ever help anyone else.. but OK... Changing the
question after it's been answered is pointless anyway though (or even rude for more substantial changes than this).
– Alex Poole Dec 6, 2017 at 18:09
ORA ERR
5
ORA-01748 only simple column names allowed here
Action you can take to resolve this issue: Remove the qualifications from the column and retry
the operation.
In your case, you are trying to refer to the table name while defining a constraint -
Attendence.ST_ROLLNO - WRONG.
It must contain a simple name without the table name or schema name.
Sir do you know how to perform DML operation on a table whoes column is type obeject ? – Ahtisham Dec 6,
2017 at 17:15
1 @Ahtisham : It is too broad question and not in the scope of a comment section of an unrelated answer. You may
google it or ask that as a separate question providing the details. And you don't have to address me as "Sir" the next
time. – Kaushik Nayak Dec 6, 2017 at 17:19