Home > Mobile >  how do I make the right references in oracle
how do I make the right references in oracle

Time:12-05

I wrote this SQL script like this and I have no idea what's missing

create table Reggister(
stdNo CHAR(5),
courseID CHAR(8),
semesterID CHAR(5),
grade CHAR(2),
mark DECIMAL(4,2) check(BETWEEN 0.00 and 100.00),
foreign key (stdNo) references student(stdNo),
foreign key (courseID) references course(courseID),
foreign key (semesterID) references semester(semesterID),
primary key (stdNo, courseID, semesterID)
);

it'll give me something like ORA-00936: missing expression

CodePudding user response:

Jeff Holt's comment is the answer. The syntax for the BETWEEN operator is:

expression [ NOT ] BETWEEN low AND high

So you're just missing the expression to be tested in the range part of the check constraint. It should be:

check(mark BETWEEN 0.00 and 100.00)

The rest of your script works when the tables and columns in your foreign key declarations are present in the schema.

CodePudding user response:

I solved it

create table Reggister(
stdNo CHAR(5),
courseID CHAR(8),
semesterID CHAR(5),
grade CHAR(2),
mark DECIMAL(4,2) check(mark BETWEEN 0.00 and 100.00),
foreign key (stdNo) references student(stdNo),
foreign key (courseID) references course(courseID),
foreign key (semesterID) references semester(semesterID)
);
  • Related