EJay
EJay

Reputation: 29

Oracle Batch Database

I'm trying to run my databases but STUDENTS AND BATCHES tables are giving the error: 'ORA-00942: table or view does not exist'. I've tried dropping them in order, but I can't tell what exactly the problem is. Forgive me if the answer is obvious, I'm new to batches

DROP TABLE students;
DROP TABLE batches;

DROP TABLE courses;
DROP TABLE faculty;


CREATE TABLE batches (
bcode varchar2(5) CONSTRAINT batches_PK PRIMARY KEY,   
ccode varchar2(5) CONSTRAINT batches_ccode_FK  REFERENCES COURSES(ccode),  
fcode varchar2(5) CONSTRAINT batches_fcode_FK  REFERENCES FACULTY(fcode),   
stdate date CONSTRAINT batches_stdate_nn not null,  
enddate date,  
timing number(1) CONSTRAINT batches_timing_chk  check( timing in (1,2,3) ),   
CONSTRAINT batches_date_chk check ( stdate <= enddate) 
);   

CREATE TABLE students (
rollno number(5) CONSTRAINT students_PK PRIMARY KEY,   
bcode varchar2(5) CONSTRAINT students_bcode_FK REFERENCES batches(bcode),   
name varchar2(30),
gender char(1) CONSTRAINT students_gender_chk check( upper(gender) in ('M','F')),   
dj date,   
phone varchar2(10),   
email varchar2(30) 
);  

CREATE TABLE courses ( 
ccode     VARCHAR2(10)  CONSTRAINT courses_PK  PRIMARY KEY, 
cname     VARCHAR2(50), 
coursefee NUMBER(6),  
prereq    VARCHAR2(100) 
);

CREATE TABLE faculty (
fcode     VARCHAR2(5)  CONSTRAINT faculty_PK PRIMARY KEY,
name      VARCHAR2(50)
);

Upvotes: 1

Views: 54

Answers (1)

zedfoxus
zedfoxus

Reputation: 37119

Create your faculty and courses tables first. Since batches depends on one of those tables, you would want to have those tables created first.

CREATE TABLE courses ( 
ccode     VARCHAR2(10)  CONSTRAINT courses_PK  PRIMARY KEY, 
cname     VARCHAR2(50), 
coursefee NUMBER(6),  
prereq    VARCHAR2(100) 
);

CREATE TABLE faculty (
fcode     VARCHAR2(5)  CONSTRAINT faculty_PK PRIMARY KEY,
name      VARCHAR2(50)
);


CREATE TABLE batches (
bcode varchar2(5) CONSTRAINT batches_PK PRIMARY KEY,   
ccode varchar2(5) CONSTRAINT batches_ccode_FK  REFERENCES COURSES(ccode),  
fcode varchar2(5) CONSTRAINT batches_fcode_FK  REFERENCES FACULTY(fcode),   
stdate date CONSTRAINT batches_stdate_nn not null,  
enddate date,  
timing number(1) CONSTRAINT batches_timing_chk  check( timing in (1,2,3) ),   
CONSTRAINT batches_date_chk check ( stdate <= enddate) 
);

CREATE TABLE students (
rollno number(5) CONSTRAINT students_PK PRIMARY KEY,   
bcode varchar2(5) CONSTRAINT students_bcode_FK REFERENCES batches(bcode),   
name varchar2(30),
gender char(1) CONSTRAINT students_gender_chk check( upper(gender) in ('M','F')),   
dj date,   
phone varchar2(10),   
email varchar2(30) 
);  

Example: http://sqlfiddle.com/#!4/91909c/1 shows the sequence of table creation

Upvotes: 2

Related Questions