我已尝试尽我所能调试此代码,以消除小错误的可能性,因为这些错误是发生这些错误的原因,但我在三个 create table 语句上不断收到两个不同的错误。
CREATE TABLE SECTION 语句在指向 course# 的第 7 行给出了一个无效标识符错误,这是我的代码:
CREATE TABLE SECTION
(SECTION# VARCHAR2(8) constraint pk_section# primary key,
TIME CHAR(5),
MAXST NUMBER(2),
ROOM VARCHAR2(14),
constraint chk_maxst check(maxst<=35),
constraint fk_crs foreign key(course#)
REFERENCES course(course#),
constraint fk_pro foreign key(empid)
REFERENCES professor(empid));
CREATE TABLE TAKES 语句在指向 section# 的第 4 行给出了一个无效标识符错误,这是我的代码:
CREATE TABLE TAKES
(GRADE CHAR(5) constraint nn_grade not null,
constraint chk_grade check(grade IN ('A','B','C')),
constraint fk_sec foreign key(section#)
REFERENCES section (section#),
constraint fk_stu foreign key(sid)
REFERENCES student(sid));
完整的上下文:
drop table professor cascade constraints;
drop table course cascade constraints;
drop table student cascade constraints;
drop table section cascade constraints;
drop table takes cascade constraints;
CREATE TABLE PROFESSOR
(NAME CHAR(15) constraint nn_name not null,
EMPID VARCHAR2(8) constraint pk_empid primary key,
PHONE NUMBER(10),
DATEHIRED DATE,
SALARY NUMBER);
CREATE TABLE COURSE
(NAME CHAR(24) constraint nn_names not null,
COURSE# CHAR(10) constraint pk_course# primary key,
CREDIT CHAR(6) constraint nn_credit not null,
COLLEGE CHAR(20),
HRS NUMBER(1),
constraint chk_credit check(credit IN('U','G')),
constraint chk_college check(college IN ('Arts and Sciences','Education','Engineering','Business')),
constraint chk_course check((credit='U' AND hrs<=4) OR (credit = 'G' AND hrs=3)),
constraint unq_course unique(name, college));
CREATE TABLE STUDENT
(SID VARCHAR2(7) constraint pk_sid primary key,
NAME CHAR(14),
ADDRESS CHAR(22),
BIRTHDATE DATE,
GRADELEVEL CHAR(2) constraint nn_glvl not null);
CREATE TABLE SECTION
(SECTION# VARCHAR2(8) constraint pk_section# primary key,
TIME CHAR(5),
MAXST NUMBER(2),
ROOM VARCHAR2(14),
constraint chk_maxst check(maxst<=35),
constraint fk_crs foreign key(course#)
REFERENCES course(course#),
constraint fk_pro foreign key(empid)
REFERENCES professor(empid));
CREATE TABLE TAKES
(GRADE CHAR(5) constraint nn_grade not null,
constraint chk_grade check(grade IN ('A','B','C')),
constraint fk_sec foreign key(section#)
REFERENCES section (section#),
constraint fk_stu foreign key(sid)
REFERENCES student(sid));
Textbook references:
[https://drive.google.com/open?id=1eDdBShzgnSjISqxByJ7FKgbkLCEwXzpd][1]
[https://drive.google.com/open?id=1WhDsgQy2xSwjxVMqDzaGOcBh7zSokneT][2]
[https://drive.google.com/open?id=12N51OCEucRn_unagqHYsqufEGK3tKJH_][3]