2015-12-06 43 views
1

我试图运行我的数据库,但学生和BATCHES表给出错误:'ORA-00942:表或视图不存在'。我试过按顺序放下它们,但我无法确定问题到底是什么。 原谅我,如果答案是显而易见的,我是新来的批次Oracle批处理数据库

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) 
); 
+0

的序列?? – aschipfl

回答

2

首先创建您的教师和课程表。由于批次取决于其中一个表,因此您希望先创建这些表。

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) 
); 

示例:http://sqlfiddle.com/#!4/91909c/1示出了该如何链接到[标签:批处理文件]表创建