Sei sulla pagina 1di 9

-University table assume zipcode has 6 digits and state has 2 letters.

CREATE TABLE University

(

University_Name VARCHAR2(20) NOT NULL , University_ID NUMBER(4) NOT NULL , University_Address_Street VARCHAR2(20), University_Address_City VARCHAR2(10), University_Address_State CHAR(2), University_Address_Zipcode VARCHAR(6), University_Phone VARCHAR2(4) , University_Email VARCHAR2

;

)

-20

ALTER TABLE University ADD CONSTRAINT University_PK PRIMARY KEY ( University_ID ) ;

CREATE TABLE College

(

College_University_ID NUMBER(4) NOT NULL , College_ID VARCHAR(4) NOT NULL , College_Name VARCHAR2(15) NOT NULL

;

)

ALTER TABLE College ADD CONSTRAINT College_PK PRIMARY KEY ( College_ID )

;

ALTER TABLE College ADD CONSTRAINT College_University_FK FOREIGN KEY

(

College_University_ID

)

REFERENCES University

(

University_ID

;

CREATE TABLE Instructor

(

Instructor_ID NUMBER(4) NOT NULL , Instructor_FName VARCHAR2(10) NOT NULL , Instructor_LName VARCHAR2(20) NOT NULL , Instructor_College_ID VARCHAR2(4) NOT NULL , Instructor_Phone VARCHAR2(4) , Instructor_Personal_ID VARCHAR(20) NOT NULL

;

)

ALTER TABLE Instructor ADD CONSTRAINT Instructor_PK PRIMARY KEY ( Instructor_ID )

ALTER TABLE Instructor

ADD CONSTRAINT FK_Person FOREIGN KEY

(

Instructor_Personal_ID,

Instructor_FName,

Instructor_LName

)

REFERENCES Person

(

 

Person_ID,

Person_FName,

Person_LName

)

;

CREATE TABLE College_Instructor_IDX

(

College_ID NUMBER(4) NOT NULL , Instructor_ID NUMBER(4) NOT NULL , Instructor_LName VARCHAR2(20) NOT NULL , Instructor_FName VARCHAR2(10) NOT NULL

;

)

ALTER TABLE College_Instructor ADD CONSTRAINT College_Instructor_IDX PRIMARY KEY ( College_ID, Instructor_ID ) ;

ALTER TABLE College_Instructor ADD CONSTRAINT Coll_Inst_CollegeID_FK FOREIGN KEY

(

College_College_ID

)

REFERENCES College

(

College_ID

)

ON DELETE CASCADE

;

#NAME?

CREATE TABLE Student

(

Student_ID NUMBER(4) NOT NULL , Student_FName VARCHAR2(10) NOT NULL , Student_LName VARCHAR2(20) NOT NULL , Student_Status VARCHAR2(10), Student_FullTime_Flag CHAR (1), Student_Advisor_ID NUMBER(4) NOT NULL , Student_Personal_ID VARCHAR(20) NOT NULL

;

)

ALTER TABLE Student ADD CONSTRAINT Student_PK PRIMARY KEY ( Student_ID )

;

ALTER TABLE Student

ADD CONSTRAINT Student_Advisor_FK FOREIGN KEY

(

Student_Advisor_ID,

Student_ID

)

REFERENCES Advisor

(

Advisor_Instructor_ID,

Advisee_Student_ID

;

)

ALTER TABLE Student ADD CONSTRAINT Student_Person_FK FOREIGN KEY

(

Student_Personal_ID,

Student_FName,

Student_LName

)

REFERENCES Person

(

 

Person_ID,

Person_FName,

Person_LName

)

;

CREATE TABLE Student_College_IDX

(

College_ID NUMBER(4) NOT NULL , Student_ID NUMBER(4) NOT NULL

;

)

ALTER TABLE Student_College ADD CONSTRAINT Student_College_IDX PRIMARY KEY ( College_ID, Student_ID ) ;

ALTER TABLE Student_College ADD CONSTRAINT Stu_Coll_StudentID_FK FOREIGN KEY

(

Student_ID

)

REFERENCES Student

(

Student_ID

)

ON DELETE CASCADE

;

ALTER TABLE Student_College

ADD CONSTRAINT Stu_COll_CollegeID_FK FOREIGN KEY

(

College_ID

REFERENCES College

(

College_ID

)

ON DELETE CASCADE

;

CREATE TABLE Course

(

Course_College_ID NUMBER(4) NOT NULL , Course_ID NUMBER(4) NOT NULL , Course_Name VARCHAR2(20) , Course_Credits NUMBER(1) NOT NULL

;

)

-- Course Credits range is from 1 to 5 ALTER TABLE Course ADD CONSTRAINT Course_PK PRIMARY KEY ( Course_ID )

;

ALTER TABLE COURSE ADD CONSTRAINT Course_Credits_Max check

(

Course_Credits <= 5

)

ADD CONSTRAINT Course_Credits_Min check

(

Course_Credits > 0

)

;

ALTER TABLE Course ADD CONSTRAINT Course_College_ID_FK FOREIGN KEY

(

College_ID

)

REFERENCES College

(

College_ID

)

ON DELETE CASCADE

;

CREATE TABLE Student_Course_IDX

(

Course_ID NUMBER(4) NOT NULL , Student_ID NUMBER(4) NOT NULL , Student_LName VARCHAR2(10) NOT NULL , Student_FName VARCHAR2(20) NOT NULL , Student_Course_Grade(3) NUMBER

;

)

ALTER TABLE Student_Course ADD CONSTRAINT Student_Course_IDX PRIMARY KEY ( Course_ID, Student_ID ) ;

ALTER TABLE Student_Course

ADD CONSTRAINT Stu_Cour_StudentID_FK FOREIGN KEY

(

Student_ID

)

REFERENCES Student

(

Student_ID

)

ON DELETE CASCADE

;

ALTER TABLE Student_Course ADD CONSTRAINT Stu_Cour_CourseID_FK FOREIGN KEY

(

Course_ID

)

REFERENCES Course

(

Course_ID

)

ON DELETE CASCADE

;

REATE TABLE Person

(

Person_FName VARCHAR2(10) NOT NULL , Person_LName VARCHAR2(20) NOT NULL , Person_ID VARCHAR(20) NOT NULL , Person_Address_Street VARCHAR2(20), Person_Address_City VARCHAR2(10), Person_Address_State CHAR(2), Person_Address_Zipcode VARCHAR(6),,

Person_Phone NUMBER(10) , Person_Email VARCHAR2(20) , Person_Sex CHAR (1) NOT NULL

;

)

ALTER TABLE Person ADD CONSTRAINT Person_PK PRIMARY KEY ( Person_ID, Person_FName, Person_LName ) ;

CREATE TABLE Advisor

(

Advisor_Instructor_ID NUMBER(4) NOT NULL , Advisee_Student_ID NUMBER(4) NOT NULL

;

)

ALTER TABLE Advisor ADD CONSTRAINT Advisor_PK PRIMARY KEY ( Advisor_Instructor_ID, Advisee_Student_ID )

ALTER TABLE Advisor ADD CONSTRAINT Adv_InstructorID_FK FOREIGN KEY

(

Advisor_Instructor_ID

)

REFERENCES Instructor

(

Instructor_ID

;

)

ALTER TABLE Advisor

ADD CONSTRAINT Adv_Student_ID_FK FOREIGN KEY

(

Advisee_Student_ID

)

REFERENCES Student

(

Student_ID

;

)

#NAME?

CREATE TABLE Student_Instructor_Course

(

PK_Stu_Inst_Course NUMBER(4) NOT NULL, Student_ID NUMBER(4) NOT NULL , Instructor_ID NUMBER(4) NOT NULL , Course_ID NUMBER(4) NOT NULL

;

)

ALTER TABLE Student_Instructor_Course ADD CONSTRAINT PK_Stu_Inst_Course PRIMARY KEY ( PK_Stu_Inst_Course ) ;

ALTER TABLE Student_Instructor_Course

ADD CONSTRAINT SIC_Student_ID_FK FOREIGN KEY

(

Student_ID

)

REFERENCES Student

(

Student_ID

;

)

ALTER TABLE Student_Instructor_Course

ADD CONSTRAINT SIC_Instructor_ID_FK FOREIGN KEY

(

Instructor_ID

)

REFERENCES Instructor

(

Instructor_ID

;

)

ALTER TABLE Student_Instructor_Course

ADD CONSTRAINT SIC_Course_ID_FK FOREIGN KEY

(

Course_ID

)

REFERENCES Course

(

Course_ID

;

)

CREATE TABLE Evaluation

(

PK_Stu_Inst_Course NUMBER(4) NOT NULL , Evaluation_Comments BLOB , Evaluation_Q1_Rating NUMBER(3), Evaluation_Q2_Rating NUMBER(3), Evaluation_Q3_Rating NUMBER(3), Evaluation_Q4_Rating NUMBER(3), Evaluation_Q5_Rating NUMBER(3)

;

)

ALTER TABLE Evaluation ADD CONSTRAINT Evaluation_PK PRIMARY KEY ( PK_Stu_Inst_Course ) ;