0

I a trying to create a script that I will run in sqlplus (Oracle Database). It should create several tables, but when I execute it, it just says that it does not recognise any command that is written. This is my code right now:

create table STUDENT(

    Name                varchar2(40) not null,
    Student_Number      number(10),
    Class               number(10),
    Major               varchar2(40),

    primary key(Student_Number)

);


create table COURSE(

    Course_name     varchar2(40) unique,
    Course_number   varchar2(40),
    Credit_hours    number(10),
    Department      varchar2(40),

    primary key(Course_number)

);


create table SECTION(

    Section_Identifier      number(10),
    Course_number           number(10) not null,
    Semester                varchar2(40) not null,
    Year                    number(10) not null,
    Instructor              varchar2(40),


    primary key(Section_Identifier)
    foreign key(Course_number) references COURSE(Course_number)

);


create table GRADE_REPORT(

    Student_Number          number(10), 
    Section_Identifier      number(10),
    Grade                   varchar2(40),

    primary key(Student_Number, Section_Identifier)
    primary key(Student_Number) references STUDENT(Student_Number)
    foreign key(Section_Identifier) references SECTION(Section_Identifier)

);


create table PREREQUISITE(

    Course_number           varchar2(40),
    Prerequisite_number     varchar2(40),

    primary key(Course_number, Prerequisite_number)
    foreign key(Course_number) references COURSE(Course_number)
    foreign key(Prerequisite_number) references COURSE(Course_number)

);

I think this code should be fine, but I do not know if I am missing somethong essential.

1 Answer 1

1

Well no, the code is not correct. You should probably debug your SQL

First off, you need to add a comma after every constraint declaration.

Secondly,

primary key(Student_Number) references STUDENT(Student_Number),

is incorrect syntax. You cannot declare a second primary key, and you cannot reference another table using the primary key constraint. That is a foreign key and needs to be written as a FK constraint.

In this situation you should probably not make your primary key a foreign key either. As each student can have multiple grade reports resulting in a 1:many relationship.

You should work on debugging your code using something like SQL Developer or Toad

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.